Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python md5 hashes comparison

Tags:

python

hash

md5

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!!

like image 460
gpestana Avatar asked Oct 23 '22 08:10

gpestana


1 Answers

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')
like image 72
lupatus Avatar answered Nov 02 '22 23:11

lupatus