Hashing, encoding and basic security · 6 / 15 Exercise Easy

Hash fingerprint of a text

Objective

A hash function turns any data into a fixed-size fingerprint. The same text always gives the same fingerprint, and changing a single character changes it completely. The hashlib module offers many algorithms.

Instructions

  • The first line has the number n of lines; each one is algorithm text, where algorithm is md5, sha1, sha256 or sha512 and the text is the rest of the line.
  • Show the fingerprint in hexadecimal (hexdigest()) of the text encoded in UTF-8. Use hashlib.new.
Input
2
md5 hola
sha256 hola mundo
Output
4d186321c1a7f0f354b297e8914ab240
0b894166d3336435c800bea36ff21b29eaa801a52f584c006c49289a0dcf6e2f

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

Start exercise