Created
March 29, 2015 18:29
-
-
Save stribika/497809617b39403dc497 to your computer and use it in GitHub Desktop.
Generate easy to remember passwords
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 -O | |
from Crypto.Random import get_random_bytes | |
from math import ceil, log2 | |
from struct import unpack | |
from sys import argv, exit | |
if __name__ == "__main__": | |
with open("/usr/share/dict/cracklib-small") as wordlist: | |
words = wordlist.readlines() | |
password = [] | |
strength = int(argv[1]) if len(argv) > 1 else 128 | |
bits = log2(len(words)) | |
n = round(strength / bits) | |
mask = (1 << ceil(bits)) - 1 | |
for i in range(n): | |
x = len(words) | |
while x >= len(words): | |
x = unpack("=Q", get_random_bytes(8))[0] & mask | |
password.append(words[x].strip()) | |
print(*password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment