WeCodeAcademy

Hashing: Fingerprints of Data

A hash function turns any input into a fixed-size fingerprint called a digest. A cryptographic hash such as SHA-256 has three key properties:

  • the same input always gives the same digest;
  • a tiny change in the input gives a completely different digest;
  • you cannot work backwards from the digest to the input.

Hashes check integrity. Download a file, hash it, and compare with the digest the publisher lists: if they match, the file was not corrupted or tampered with. Note a hash is not encryption: there is no key and nothing to decrypt.

Examplepython
Open in editor »
Quick check

What happens to a SHA-256 digest if one character of the input changes?

Your turn: write the code

Print the first 12 characters of the SHA-256 hex digest of the word 'security'.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.