gpestana
gpestana

Reputation: 365

Python md5 hashes comparison

I'm trying to compare hashes using Python, but I'm stuck with this problem:

print ('-- '+hashesFile[h])
print ('-> ' +hashlib.md5(wordsFile[j]).hexdigest())   

-- 5d21e42d34fc1563bb2c73b3e1811357
-> 5d21e42d34fc1563bb2c73b3e1811357

But this comparison is never true:

if (hashesFile[h] == hashlib.md5(wordsFile[j]).hexdigest()):
 print ('ok')

I searched for a solution and tried to encode the string before compare them, but is don't work anyway.

Cheers!!

Upvotes: 5

Views: 4047

Answers (1)

lupatus
lupatus

Reputation: 4248

try to print both as:

print '-- %r' % hashesFile[h]
print '-> %r' % hashlib.md5(wordsFile[j]).hexdigest())  

then you'll see whats really inside.

I suppose that this will work for you:

if (hashesFile[h].strip() == hashlib.md5(wordsFile[j]).hexdigest()):
    print ('ok')

Upvotes: 3

Related Questions