Skip to content

Instantly share code, notes, and snippets.

@inky
Created May 25, 2014 17:11
Show Gist options
  • Save inky/7d869ac79ce36ee7dd49 to your computer and use it in GitHub Desktop.
Save inky/7d869ac79ce36ee7dd49 to your computer and use it in GitHub Desktop.
$ python secret123.py
f3M8VZEHb2/VAuKJScJAMYNuiawQr8q2^%s+K@ShK2M
#!/usr/bin/env python
from base64 import b64encode
from hashlib import sha256 as sha
INPUT_BYTE_COUNT = 4096
REPLACE = {
'O': '@',
'0': '$',
'o': '%',
'1': '^',
'l': '&',
'I': '*',
}
def replace_chars(s):
for i, j in REPLACE.items():
s = s.replace(i, j)
return s
def pwgen():
random_bytes = open('/dev/random').read(INPUT_BYTE_COUNT)
assert len(random_bytes) == INPUT_BYTE_COUNT
digest = sha(random_bytes).digest()
return replace_chars(b64encode(digest).rstrip('='))
if __name__ == '__main__':
print pwgen()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment