Update:

Python 3 Version can be found on GitHub.

Diceware Passphrase Generator – Python 2.7

It has been a while since I have done anything with Python so as a quick easy ‘get back into it’ I though I would create a Diceware Passphrase Generator. This is not a truly secure implementation as I am only using the python random function, as this quote from the Python Document Library explains:

Warning: The pseudo-random generators of this module should not be used for security purposes. Use os.urandom() or SystemRandom if you require a cryptographically secure pseudo-random number generator.

diceware passphrase

I will be modifying the script to use the os.urandom() function and will post it here when I do.

The wordlist I used can be found here; more information about Diceware Passphrases can be read here.

And here is the code:

import random

def dicenumber():
    diceout = ""
    for i in range(5): # 5 dice rolls
        diceout += `random.randint(1,6)` # add result of dice roll to variable
    return diceout

def diceware(x):
    wordlist = open('diceware.wordlist.asc', 'r')
    for line in wordlist:
        if line.startswith(x):
            wordlist.close()
            return line

for i in range(4): print diceware(dicenumber()), # increase number for longer passphrases