Created
November 16, 2017 01:08
-
-
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+
This file contains 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
#!/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