Last active
August 29, 2015 14:22
-
-
Save sunoru/07448074db9f47165e96 to your computer and use it in GitHub Desktop.
This file contains 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/python3 | |
# -*- coding:utf-8 -*- | |
# filename: pwdgen.py | |
import sys | |
import string | |
def main(): | |
if len(sys.argv) > 1: | |
l = int(sys.argv[1]) | |
else: | |
l = 16 | |
if len(sys.argv) > 2: | |
q = int(sys.argv[2]) | |
else: | |
q = 1 | |
op = string.ascii_letters + string.digits | |
ol = len(op) | |
for i in range(q): | |
with open('/dev/urandom', 'rb') as fi: | |
xs = fi.read(l) | |
a = '' | |
for x in xs: | |
a += op[x * ol // 256] | |
print(a) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment