Hash functions.
A blender that turns anything into a fixed-size fingerprint.
A hash function takes any input at all — a word, a whole movie file, a password — and crunches it into a short, fixed-size string of characters: its fingerprint.
Two rules make it useful. The same input always produces the same fingerprint. And changing the input even slightly produces a completely different one, with no resemblance to the old.
- In it goes.1
Feed in anything at all — a single letter, a whole book, a 4 GB video.
- 2
The hash function is the blender: it mixes and scrambles every byte.
- 3
Out comes a short fingerprint, always the same length whatever you put in.
- One typo, brand-new print.4
Same input, same fingerprint. Change one letter and it’s utterly different.
- 5
It only runs forwards — there’s no un-blend button, which is why passwords are stored this way.
- Shelf 7. No searching.6
Use the fingerprint as an address and you jump straight to a value — instant lookups.
Why one-way matters
You can compute a fingerprint in an instant, but you cannot work backwards from the fingerprint to the original — there is no un-blend button. That is why systems store the hash of your password, not the password itself. When you log in, they hash what you typed and compare fingerprints, so even a stolen database does not hand over your actual password.
It is also how you verify a download was not tampered with: compare the file’s fingerprint to the published one.
Instant lookups
The other big use is speed. A hash table turns a key into a fingerprint and uses it as an address, so it can jump straight to where a value is stored instead of searching. That is what makes dictionaries, sets, and caches feel instant, and it is the same idea behind splitting data across servers by a hashed key.