Skip to content

Instantly share code, notes, and snippets.

@lahwran
Last active August 29, 2015 14:08
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 lahwran/1606af72cf091ac8647e to your computer and use it in GitHub Desktop.
Save lahwran/1606af72cf091ac8647e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import random
random = random.SystemRandom()
dictionary = open('/usr/share/dict/words', 'r').read().split()
dictionary = [w.lower() for w in dictionary if len(w) < 10]
# reasoning for these parameters:
# http://www.wolframalpha.com/input/?i=%28%28119%2C000+**+5+*+500+**+3%29+%2F+%287%21+*+50%29%29+**+%281%2F18%29+%3E+36
# ((119,000 ** 5 * 500 ** 3) / (7! * 50)) ** (1/18) > 36
# 500 is the estimated number of stopwords in common use
assert len(set(dictionary)) > 119000, "dictionary too small!"
equiv_passwordbase = 36
equiv_passwordlen = 18
chooseyness = 50
offered_word_count = 7
complex_word_count = 5
stopword_count = 3
practice_amount = 15
def check(acceptable, phrase_words):
return (
len([w for w in phrase_words if w in acceptable]) >= complex_word_count
and len(acceptable.split()) >= stopword_count + complex_word_count)
print "variations must contain spaces between words,"
print "and must use at least", complex_word_count,
print "of the", offered_word_count ,"offered words."
print "variations must contain at least", stopword_count,
print "of your own custom-chosen stopwords (trivial words like 'the', 'of', etc.)."
for x in xrange(chooseyness):
phrase_words = [random.choice(dictionary) for y in xrange(offered_word_count)]
phrase = ' '.join(phrase_words)
acceptable = raw_input("is %r acceptable? type a variation: " % phrase)
if not check(acceptable, phrase_words):
print "missing (a )word(s), skipping"
continue
else:
for z in range(15):
v = raw_input("retype variation: ").lower()
if not check(acceptable, phrase_words):
print "missing (a )word(s), skipping"
break
else:
print
print " kay, use that password. no more will be offered."
print
break
else:
print
print
print " WARNING: DO NOT RERUN THIS PROGRAM FOR THIS PASSPHASE CHOICE."
print " CHOOSE ONLY FROM ABOVE OPTIONS. YOU ARE BEING TOO CHOOSEY."
print
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment