Created
April 5, 2013 11:20
-
-
Save moshekaplan/5318560 to your computer and use it in GitHub Desktop.
Simple salting to generate x-digit codes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import hashlib | |
| salt = "This is a super secret salt. Nobody should ever be able to guess this.6rAtas7swe9ach6rAtas7swe9achXrAtas7swe9ach6rAtas7swe9ach6rAtas7swe9ach6rAtas7swe9ach" | |
| def get_code(number, length): | |
| """Returns the first length bytes of the generated 'code'""" | |
| return hashlib.sha512(str(number) + str(salt)).hexdigest()[:length] | |
| for i in range(10): | |
| print get_code(i, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment