i’m trying to build an MD5 ‘cracker’ and using two different scripts to do it, the first takes a list of words from a wordlist (huge word list.txt), then hashes them and writes them to another file(WordsHash.txt). The second then takes a user defined word, hashes it and compares it to the hashes in WordHash.txt, but i’m getting different hashes for ‘the same’ string.
first script:
import hashlib
hashes = open("WordsHash.txt", 'w')
m = hashlib.md5()
with open("huge word list.txt") as words:
words = words.readlines()
print "processing..."
for line in words:
line = line.replace("\n", "")
m.update(line)
word_hash = m.hexdigest()
line = "%s %s\n" % (line, word_hash)
hashes.write(line)
print "done."
hashes.close()
and the second script:
import hashlib
f = open('WordsHash.txt')
p = '\'due'
password = hashlib.md5()
password.update(p)
password = password.hexdigest()
print "%r %r" %(password, p)
for line in f:
lines = line.split(" ")
lines[1] = lines[1].replace("\n", "")
word_hash = lines[1]
if word_hash == password:
print "found it, %s" % line
exit(0)
You need to create a new md5 object for each thing you want to hash. Otherwise, you’re are including the previous hashing work when you compute subsequent hashes.
Given the list “apple”, “banana”, “pear”, your processor is giving the hashes for “apple”, “applebanana”, and “applebananapear”.