1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import hashlib, sys
m = hashlib.sha256()
hash = ""
hash_file = 'hash.txt'
wordlist = 'm.txt'
try:
hashdocument = open(hash_file,"r")
except IOError:
print ("Invalid file.")
input()
sys.exit()
else:
hash = hashdocument.readline()
hash = hash.replace("\n","")
try:
wordlistfile = open(wordlist,"r")
except IOError:
print ("Invalid file.")
input()
sys.exit()
else:
pass
for line in wordlistfile:
m = hashlib.sha256() #flush the bufer (thiscaused a massive problem when placed at the beginning of the script, because the buffer kept getting overwritten, thus comparing incorrect hashes)
line = line.replace("\n","")
m.update(line.encode(wordlistfile.encoding))
word_hash = m.hexdigest()
if word_hash == hash:
print ("Collision! the word corresponding to the given hash is", line,)
input()
sys.exit()
print ("the hash given does not correspond to any supplied word in the wordlist.")
input()
sys.exit() |
Partager