Skip to content

Instantly share code, notes, and snippets.

@poppingtonic
Last active August 1, 2019 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poppingtonic/c7e9a91256c9c5db1676aa3c240531cf to your computer and use it in GitHub Desktop.
Save poppingtonic/c7e9a91256c9c5db1676aa3c240531cf to your computer and use it in GitHub Desktop.
This script generates a list of 9 words as a "strong-enough" passphrase generator. My attempt, based on python 3.6's secrets module, to justifiably disobey the Diceware recommendation against computer-based RNGs: http://world.std.com/~reinhold/diceware.html
#!/usr/bin/env python
# requires python 3.6 and requests
import os
import re
import secrets
import requests
wordlist_file = 'diceware.wordlist.asc'
if not os.path.isfile(wordlist_file):
print('Reticulating splines...\n')
data = requests.get('http://world.std.com/~reinhold/diceware.wordlist.asc').text
with open(wordlist_file, 'w') as f:
f.write(data)
random_integer_list = [secrets.choice(range(1, 7)) for i in range(45)]
f = lambda A, n=5: [A[i:i+n] for i in range(0, len(A), n)]
grouped_codes = f(random_integer_list)
passphrase_codes = map(lambda elt: r''.join(str(x) for x in elt), grouped_codes)
passphrase = []
for code in passphrase_codes:
for line in open(wordlist_file, 'r'):
if re.match(code, line):
passphrase.append(line.strip().split('\t')[1])
print(' '.join(passphrase))
# #### download beale.wordlist.asc from http://world.std.com/~reinhold/diceware.html
@rwanyoike
Copy link

Relevant XKCD ᕕ( ᐛ )ᕗ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment