Last active
January 4, 2018 17:54
-
-
Save alertedsnake/a98d1aae9c19eff7db62a88195e7ff1f to your computer and use it in GitHub Desktop.
xkcd #936 password generator
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/env python3 | |
""" | |
Random password generator, ala https://xkcd.com/936/ | |
The wordlist is assumed to be a list of words in the language of your choice, | |
of the sizes of your choice. I got mine out of aspell:: | |
aspell dump master | \ | |
sed -e "s/'s$//" -e '/^[A-Z]/d' -e '/^.\{4,6\}$/!d' | \ | |
sort -u > wordlist.txt | |
Kinda figured 4-6 were good word lengths. | |
""" | |
import argparse | |
import os | |
import random | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--wordlist', '-w', type=str, default='~/etc/wordlist.txt') | |
parser.add_argument('--number', '-n', type=int, default=4, help="number of words") | |
args = parser.parse_args() | |
with open(os.path.expanduser(args.wordlist), 'r') as f: | |
words = f.readlines() | |
parts = [] | |
for i in range(args.number): | |
parts.append(random.choice(words).strip()) | |
print(' '.join(parts)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment