Comparing Python md5 hashes

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

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

-- 5d21e42d34fc1563bb2c73b3e1811357
-> 5d21e42d34fc1563bb2c73b3e1811357

But this comparison is never performed:

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

I searched for a solution and tried to encode the string before comparing them, but still does not work.

Hooray!!

+5
source share
1 answer

try typing both:

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

then you will see what's inside.

I believe this will work for you:

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

All Articles