Last active
April 28, 2017 17:44
-
-
Save craSH/9ec4b43aa61956d530cb to your computer and use it in GitHub Desktop.
Select easy to use passphrases based on the diceware list; but not their selection methodology [lazy]
This file contains hidden or 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 python | |
| """ | |
| Select easy to use passphrases based on the diceware list; but not their selection methodology [lazy]. | |
| Place the diceware and beale wordlists (GPG signed is fine) in /usr/share/dict before use. | |
| * Diceware list: http://world.std.com/~reinhold/diceware.wordlist.asc | |
| * Alternative Beale list: http://world.std.com/~reinhold/beale.wordlist.asc | |
| * EFF List (Large): https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt | |
| * EFF List (Small): https://www.eff.org/files/2016/09/08/eff_short_wordlist_1.txt | |
| Copyleft 2015 Ian Gallagher <[email protected]> | |
| """ | |
| import sys, os, random | |
| list_file = "/Users/igallagher/Library/crash/{list_name}.wordlist.asc" | |
| supported_lists = [ | |
| 'diceware', | |
| 'beale', | |
| 'eff_large', | |
| 'eff_short' | |
| ] | |
| def main(): | |
| import optparse | |
| parser = optparse.OptionParser(usage="Usage: %prog [-l] [-u <list>] [-n] <num_words>") | |
| parser.add_option('-n', '--num_words', dest='num_words', type='int', | |
| default=6, help='Number of words in passphrase (default 6) - ' \ | |
| 'takes precedence over positional argument') | |
| parser.add_option('-l', '--list', dest='list', type='string', | |
| default='diceware', help='List to use (diceware, beale, eff)') | |
| parser.add_option('-u', '--unique', dest='unique', action='store_true', | |
| help='Guarantee unique words (no repeats)') | |
| (options, args) = parser.parse_args() | |
| if(6 == options.num_words and len(args) > 0 and args[0].isdigit()): | |
| # -n probably not specified, use positional argument for num_words | |
| options.num_words = int(args[0]) | |
| if(0 >= options.num_words): | |
| print >> sys.stderr, "Number of words must be greater than 0." | |
| return(1) | |
| if(options.list not in supported_lists): | |
| print >> sys.stderr, "Unsupported list type ({bad_list}) specified, currently only the following lists are " \ | |
| "supported: {lists}".format(bad_list=options.list, lists=', '.join(supported_lists)) | |
| return(1) | |
| num_words = options.num_words | |
| diceware_words = list() | |
| random_passwords = list() | |
| with open(list_file.format(list_name=options.list), 'r') as fh: | |
| for line in fh: | |
| line = line.strip() | |
| if(line[:5].isdigit()): | |
| diceware_words.append(line.split('\t', 1)[-1]) | |
| for i in range(num_words): | |
| if(options.unique): | |
| try: | |
| rand_word = diceware_words.pop(random.randint(0, len(diceware_words) - 1)) | |
| random_passwords.append(rand_word) | |
| except ValueError as ex: | |
| print "Ran out of possible values to pull from, try again with a lower number of words specified." | |
| sys.exit(1) | |
| else: | |
| rand_word = random.choice(diceware_words) | |
| random_passwords.append(rand_word) | |
| print ' '.join(random_passwords) | |
| return(0) | |
| if '__main__' == __name__: | |
| sys.exit(main()) | |
| # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment