Last active
June 25, 2022 16:30
-
-
Save jreisinger/833d02c2f544439e481b2e5ab5171baa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib, sys | |
from hashlib import md5 | |
def hash_with_all_guaranteed_algoritms(msg: bytes): | |
"""hash functions guaranteed to be available for all platforms""" | |
for algo in sorted(hashlib.algorithms_guaranteed): | |
try: | |
h = hashlib.new(algo) | |
h.update(msg) | |
print("{:10} {}".format(algo, h.hexdigest())) | |
except Exception as e: | |
print("{} error: {}".format(algo, e), file=sys.stderr) | |
def md5_collision(msg1: bytearray, msg2: bytearray) -> bool: | |
if msg1 == msg2: | |
return False | |
if md5(msg1).digest() == md5(msg2).digest(): | |
return True | |
return False | |
if __name__ == "__main__": | |
msg = b'hello' | |
hash_with_all_guaranteed_algoritms(msg) | |
msg1 = bytearray.fromhex('d131dd02c5e6eec4693d9a0698aff95c2fcab58712467eab4004583eb8fb7f8955ad340609f4b30283e488832571415a085125e8f7cdc99fd91dbdf280373c5bd8823e3156348f5bae6dacd436c919c6dd53e2b487da03fd02396306d248cda0e99f33420f577ee8ce54b67080a80d1ec69821bcb6a8839396f9652b6ff72a70') | |
msg2 = bytearray.fromhex('d131dd02c5e6eec4693d9a0698aff95c2fcab50712467eab4004583eb8fb7f8955ad340609f4b30283e4888325f1415a085125e8f7cdc99fd91dbd7280373c5bd8823e3156348f5bae6dacd436c919c6dd53e23487da03fd02396306d248cda0e99f33420f577ee8ce54b67080280d1ec69821bcb6a8839396f965ab6ff72a70') | |
if md5_collision(msg1, msg2): | |
print("MD5 collision!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment