Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading