Skip to content

Instantly share code, notes, and snippets.

@ayharano
Created November 16, 2017 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayharano/0bd7cd349947c7afc1fd22c3fd022160 to your computer and use it in GitHub Desktop.
Save ayharano/0bd7cd349947c7afc1fd22c3fd022160 to your computer and use it in GitHub Desktop.
Based on XKCD-style passphrase recipe from https://docs.python.org/3/library/secrets.html#recipes-and-best-practices. Python 3.6+
#!/usr/bin/python3
"""
Based on XKCD-style passphrase recipe from
https://docs.python.org/3/library/secrets.html#recipes-and-best-practices.
"""
import secrets
TRUNCATE = 64
with open('/usr/share/dict/WORDS') as f:
WORDS = [word.strip() for word in f]
SEED = str(secrets.choice(range(10))).join(secrets.choice(WORDS)
for i in range(12))
LETTERS = []
for l in SEED:
LETTERS.append(l.upper()
if secrets.randbits(1) % 2 == 0
else l.lower())
FINAL = ''.join(LETTERS)[::-1][:TRUNCATE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment