Pure Programmer
Blue Matrix


Cluster Map

Project: One-Way Hash

A one-way hash is a small value that we compute based on a larger amount of data. It is also known as a digest.

One-way hashes are useful in cryptographic contexts because good ones can't be used to deduce the original data from the hash. We could, for example, store the one-way hash values of passwords in a file and use them to confirm that the password entered by a user hashes to the correct value stored in the file. This way we don't expose the actual passwords in the file. They can also be used for digital signatures and checksums.

They are also useful in creating hash tables used to implement maps or dictionaries. The one-way hash computed from a given key will correspond to the index in the array where the corresponding value will be stored in the hash table.

Write a function that implements the [[https://en.wikipedia.org/wiki/MD5|MD5]] hash algorithm. You main program should accept a filename on the command line, read the file in binary mode, compute the MD5 hash and print the MD5 hash in hexadecimal on the console.

See [[https://en.wikipedia.org/wiki/Cryptographic_hash_function|Cryptographic Hash]]
See other project

Output
$ python3 OneWayHash.py ../../data/text/GettysburgAddress.txt 6AA2D0C76C168EFD96AC23E5211318A1 $ python3 OneWayHash.py ../../data/text/UnicodeTest.utf8 09AAD1C135254E52A5AB48FE176E9635 $ python3 OneWayHash.py ../../data/text/USConstitution.txt 4455CBB6CC28F0DB78257DDB0A870101 $ python3 OneWayHash.py ../../data/binary/RandomBytes1M.bin 759F80D5BFEEE13BAAE16F2E4105A54C $ python3 OneWayHash.py ../../data/images/GlowingCat.png 64E3953249B63C18FDF741B8934E1627 $ python3 OneWayHash.py ../../data/audio/Cantaloop.mp3 E16A2C97C70F724D2146A90ED8856ED5

Solution