Created
May 25, 2014 17:11
-
-
Save inky/7d869ac79ce36ee7dd49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ python secret123.py | |
| f3M8VZEHb2/VAuKJScJAMYNuiawQr8q2^%s+K@ShK2M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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