Hashing, encoding and basic security · 7 / 15 Exercise Medium

Check the integrity of a message

Objective

Fingerprints are used to detect that data has changed: the fingerprint is published with the data and whoever receives it recomputes and compares it. To compare fingerprints use hmac.compare_digest, which does not reveal through response time where the first difference is.

Instructions

  • The first line has the number n of lines; each one is fingerprint text: the expected SHA-256 fingerprint (in hexadecimal) and the text, which is the rest of the line.
  • Show OK if the fingerprint of the text matches (ignoring case in the expected one) or CORRUPT if not.
Input
2
0b894166d3336435c800bea36ff21b29eaa801a52f584c006c49289a0dcf6e2f hola mundo
b221d9dbb083a7f33428d7c2a3c3198ae925614d70210e28716ccaa7cd4ddb79 adios
Output
OK
CORRUPT

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise