Skip to content

Instantly share code, notes, and snippets.

@moshekaplan
Created April 5, 2013 11:20
Show Gist options
  • Select an option

  • Save moshekaplan/5318560 to your computer and use it in GitHub Desktop.

Select an option

Save moshekaplan/5318560 to your computer and use it in GitHub Desktop.
Simple salting to generate x-digit codes.
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