I would like to show my students that MD5 collides the two integer "messages" given here. This is my original demonstration for Python 2.7:
from hashlib import md5
m1 = "d131dd02c5e6eec4693d9a0698aff95c2fcab58712467eab4004583eb8fb7f8955ad340609f4b30283e488832571415a085125e8f7cdc99fd91dbdf280373c5bd8823e3156348f5bae6dacd436c919c6dd53e2b487da03fd02396306d248cda0e99f33420f577ee8ce54b67080a80d1ec69821bcb6a8839396f9652b6ff72a70"
m2 = "d131dd02c5e6eec4693d9a0698aff95c2fcab50712467eab4004583eb8fb7f8955ad340609f4b30283e4888325f1415a085125e8f7cdc99fd91dbd7280373c5bd8823e3156348f5bae6dacd436c919c6dd53e23487da03fd02396306d248cda0e99f33420f577ee8ce54b67080280d1ec69821bcb6a8839396f965ab6ff72a70"
# differences ^ ^ ^ ^ ^ ^
print md5(m1.decode("hex")).hexdigest()
print md5(m2.decode("hex")).hexdigest()
As expected, it prints twice 79054025255fb1a26e4bc422aef54eb4.
Now when I try to translate the last two lines into Python 3.5 as:
print(md5(int(m1, 16)).hexdigest())
print(md5(int(m2, 16)).hexdigest())
All I get is a TypeError: object supporting the buffer API required message. The method decode no longer works in Python 3, but I am not sure it's a good idea to replace it by int(m, base) as above. May be the problem is there, and not with the hash function API?