Advertisement
Guest User

hashword

a guest
Oct 28th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. """Produces a unique, secure password from a site name and a secure Master Passphrase."""
  4.  
  5. import hashlib
  6.  
  7. # for python3 change raw_input to input
  8. print("""Enter the Site Name. If using the entire address, be aware that sites are
  9. increasingly moving from http to https, which would alter the result.""")
  10. site_name = raw_input('>> ')
  11. print("""Enter your Master Passphrase. This needs to be very secure, in cases someone
  12. knows/guesses you're using this. Diceware is recommended:
  13. http://world.std.com/~reinhold/diceware.html""")
  14. sekrit = raw_input('>> ')
  15.  
  16. combined_string = "%s~%s" % (site_name, sekrit)
  17. md = hashlib.md5()
  18. md.update(combined_string)
  19. hex_string = md.hexdigest()
  20.  
  21. print("MD5 hash:\n%s" % hex_string)
  22.  
  23. # This grabs the last 16 (of 32) digits. Change the slice to grab different ones.
  24. short_string = hex_string[-16:]
  25. print("16 digit:\n%s" % short_string)
  26.  
  27. # This part both obsfucates that we're using hexidecimal numbers, and (nearly always) adds
  28. # in some special characters for finicky sites
  29. # change/rearrange the 'Y' part of each 'x':'Y' pair to mix things up (keep the quotes!)
  30. # Note every nth number is changed to a special character, and every nth letter is uppercased
  31. # or changed to a value outside the hexadecimal range (>a-f)
  32. special_dict = {'0':'ยข','1':'~','2':'!','3':'@','4':'#','5':'$','6':'%','7':'^','8':'&','9':'*'}
  33. alpha_dict ={'a':'G','b':'L','c':'m','d':'t','e':'V','f':'x'}
  34. pwd_list = []
  35. # Making this number too high reduces the chances of a special character (which some sites require)
  36. nth = 3
  37. use_dict = True
  38.  
  39. for x in range(len(short_string)):
  40.     i = short_string[x]
  41.     if ((x+1) % nth != 0):
  42.         pwd_list.append(i)
  43.     elif i.isdigit():
  44.         pwd_list.append(special_dict[i])
  45.     else:
  46.         if use_dict:
  47.             pwd_list.append(alpha_dict[i])
  48.         else:
  49.             pwd_list.append(i.upper())
  50.         use_dict = not use_dict
  51. pwd_string = ''.join(pwd_list)
  52.  
  53. # We should end up with a decent password that's reproducible, unique, and secure
  54. print("Obsfucated 16 digit:\n%s" % pwd_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement