Tech●●●●●Difficulty 2 of 5

How do computers tell a file hasn't been changed?

Change a single letter in a file and its digital fingerprint turns into complete gibberish — that's the trick behind checking downloads, passwords, and even Bitcoin.

▶ Start the story

When you download a file, how would you know if even one bit of it got corrupted or swapped along the way? You usually don't have the original to compare it with byte by byte, so computers run the file through a cryptographic hash function, which crunches any input, however large, into a short, fixed-size fingerprint. The same input always produces the same fingerprint, so two copies of a file match only if their hashes match.

What makes this fingerprint trustworthy is that a tiny change in the input results in a very different hash, so even flipping one letter scrambles the output completely. That's why hash digests are sometimes published on websites so people can verify a download matches the original after the fact: if the published hash and the one you compute locally disagree, something changed.

A hash function also has to resist being gamed. It should be hard to find any input that produces a given hash, hard to find a second input matching an existing one's hash, and hard to find any two different inputs that collide on the same hash. Collisions are the easiest of these to hunt for, thanks to a trick called the birthday attack, so a hash meant to resist them must be at least twice as long as one that only has to resist being reversed.

2x

collision resistance needs a hash twice as long as preimage resistance

Hash functions don't stay strong forever, and trusting an old one is a classic mistake. Collisions in MD5, once widely used, can now be calculated within seconds, and in February 2017 Google announced a collision in SHA-1, which is now considered broken. The same one-way trick also powers Bitcoin mining, where computers hunt for inputs whose hashes meet a target to prove they did the work.

Quiz me

0/3

  1. 1.Why can comparing hashes reveal even a tiny change to a file?
  2. 2.Why do cryptographers require a hash value to be at least twice as long for collision resistance as for preimage resistance?
  3. 3.In the Alice-and-Bob thought experiment, what does Alice's hash prove?

Recap

Same input always gives the same hash; a different input almost never gives the same hash by accident.

Surprising fact · Changing a single letter anywhere in a huge file produces a completely different, unrecognizable hash.

Sources (1)

No source, no claim. Every fact in this lesson (17 claims) cites at least one of these.

  1. [1]Cryptographic hash function · Wikipedia
More lessons in 💻 Tech (3) See all tech lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗