Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Random password generator with a default entropy of 84 bits.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, string
def random_password(length=14):
Random password generator.
Default generated password will have an entropy of 84 bits.
For each character in the password, generate a random byte, reduce the
integer value to modulo 64 and use the result as an index on the character
In a 64 character pool, each character will have an entropy of 6 bits.
With a lenght of 14 characters the total entropy is 84 bits:
log2(64) * 14 = 84 bits
The difference between 13 and 14 characters can be several years to
brute force.
characters = string.ascii_letters + string.digits + '+/'
l = list()
for x in xrange(length):
i = ord(os.urandom(1))%len(characters)
c = characters[i]
return ''.join(l)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment