skip420

hash_cracker.py

Feb 22nd, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #hash_cracker.py
  2.  
  3.  
  4.  
  5. #Begin Hash Cracker.py
  6.  
  7. import hashlib, sys
  8. m = hashlib.md5()
  9. hash = ""
  10. hash_file = raw_input("What is the file name in which the hash resides?  ")
  11. wordlist = raw_input("What is your wordlist?  (Enter the file name)  ")
  12. try:
  13.     hashdocument = open(hash_file,"r")
  14. except IOError:
  15.     print "Invalid file."
  16.     raw_input()
  17.     sys.exit()
  18. else:
  19.     hash = hashdocument.readline()
  20.     hash = hash.replace("\n","")
  21.    
  22. try:
  23.     wordlistfile = open(wordlist,"r")
  24. except IOError:
  25.     print "Invalid file."
  26.     raw_input()
  27.     sys.exit()
  28. else:
  29.     pass
  30. for line in wordlistfile:
  31.     m = hashlib.md5()  #flush the buffer (this caused a massive problem when placed at the beginning of the script, because the buffer kept getting overwritten, thus comparing incorrect hashes)
  32.     line = line.replace("\n","")
  33.     m.update(line)
  34.     word_hash = m.hexdigest()
  35.     if word_hash==hash:
  36.         print "Collision!  The word corresponding to the given hash is", line,
  37.         raw_input()
  38.         sys.exit()
  39.  
  40. print "The hash given does not correspond to any supplied word in the wordlist."
  41. raw_input()
  42. sys.exit()
Add Comment
Please, Sign In to add comment