Skip to content

Instantly share code, notes, and snippets.

@moble
Created January 9, 2015 06:42
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 moble/b61b565a9a9a5ec8a35c to your computer and use it in GitHub Desktop.
Save moble/b61b565a9a9a5ec8a35c to your computer and use it in GitHub Desktop.
Generate passphrase randomly, but memorably
#! /usr/bin/env python
"""Generate a sequence of random words for use in a password/passphrase
On my Mac, the `words` file referenced in the script has 235886 (roughly 2**18)
entries. If you select N of those words randomly, you get roughly 18*N bits of
entropy for a password.
I like to generate a list about 10 words long, then choose about 6 of them to
form a sentence -- a ridiculous sentence, but still a sentence. You might have
to learn some new words, and conjugate verbs, etc. This makes it easy to
remember, but still impractical to guess. Use capitalization, spaces between
words, and relevant punctuation -- or not -- for another few bits of entropy,
and to ease memorization if you see fit.
See also <https://xkcd.com/936/>, though he apparently assumes a dictionary of
about 2000 words, and a password of 4 words; the dictionary used here is far
stronger. Bonus points for translating each word into another random language,
which has the effect of multiplying the number of bits by the number of random
languages.
This, of course, is good for your important passphrases; for online passwords,
use a password manager, like LastPass or Password Safe.
"""
import random
word_file = "/usr/share/dict/words"
words = open(word_file).read().splitlines()
for i in range(10):
print(random.choice(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment