Created
December 1, 2015 20:10
-
-
Save friek/d0c3ca56cc4ef8dc98c8 to your computer and use it in GitHub Desktop.
Revisions
-
friek created this gist
Dec 1, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/env python import crypt import random import string import sys PASSWORD_CHARS = string.ascii_uppercase + string.ascii_lowercase + string.digits MD5_SALT_CHARS = PASSWORD_CHARS + '/' DES_SALT_CHARS = string.ascii_uppercase + string.ascii_lowercase def random_string(N, charset=PASSWORD_CHARS): # http://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python return ''.join(random.choice(charset) for _ in range(N)) if __name__ == '__main__': pw_len = 9 if len(sys.argv) > 1: pw_len = int(sys.argv[1]) password = random_string(pw_len) # This only works when the libc crypt function supports it. md5 = crypt.crypt(password, '$1$' + random_string(7, MD5_SALT_CHARS) + '$') des = crypt.crypt(password, random_string(2, DES_SALT_CHARS)) print("Password: {0}\nMD5: {1}\nDES: {2}".format(password, md5, des))