MD5: Why am I getting different results for the same string?

I expected the following code to return the same result in each case since the string values are the same but instead got a different result each time. What can I do (if anything) to address this?

import hashlib

a = 'some text'
b = 'some text'
hashA = hashlib.md5(b'{a}').hexdigest()[:8]
hashB = hashlib.md5(b'{b}').hexdigest()[:8]
hashT = hashlib.md5(b'some text').hexdigest()[:8]

print(hashT) # 552e21cd
print(hashA) # e78fce13
print(hashB) # 09b94c63
print (a==b) # True

>Solution :

Because the prefix is f for formatted strings. a, b and ‘some text’ are different.

Leave a Reply