Skip to content

Instantly share code, notes, and snippets.

@zerodi
Created August 7, 2020 16:04
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 zerodi/4ca1064a88769bef49007fb13e38797f to your computer and use it in GitHub Desktop.
Save zerodi/4ca1064a88769bef49007fb13e38797f to your computer and use it in GitHub Desktop.
Passphrase generator based on EFF wordlist. Also can read string of numbers and show you words from wordlist
#!/usr/bin/env python3
#####
#
# Passphrase generator based on EFF wordlist
# Can generate new array of words and string of numbers for it
# Also can read string of numbers and show you words from wordlist
#
#####
import urllib.request
import random
import argparse
def read_word_list():
link = 'https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt'
file = urllib.request.urlopen(link).read()
return dict(line.decode('utf8').split('\t') for line in file.splitlines())
def get_new_password(num):
word_dict = read_word_list()
keys = list(word_dict.keys())
random.shuffle(keys)
word_list = []
num_list = []
for n in range(num):
key = keys[n]
word = word_dict.get(key)
num_list.append(key)
word_list.append(word)
print(key, word)
print('')
print(''.join(num_list))
print(' '.join(word_list))
def read_numstring_to_words(numstring):
word_list = []
num_list = []
wrong_code = False
while True:
num_list.append(int(numstring[:5]))
numstring = numstring[5:]
if len(numstring) == 0:
break
elif len(numstring) < 5:
wrong_code = True
break
if wrong_code:
print('Invalid length')
else:
print(num_list)
word_dict = read_word_list()
for num in num_list:
word_list.append(word_dict[str(num)])
print(''.join(word_list))
def main(command_line=None):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='command')
parser_new = subparsers.add_parser('new', help='generate new password')
parser_new.add_argument('NUMBER', type=int, default=6, help='number of words which you need (default = 6)')
parser_read = subparsers.add_parser('read', help='get words from number string')
parser_read.add_argument('NUMSTRING', type=int, help='string of numbers (without spaces)')
args = parser.parse_args(command_line)
if args.command == 'new':
get_new_password(args.NUMBER)
elif args.command == 'read':
read_numstring_to_words(str(args.NUMSTRING))
else:
parser.print_help()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment