Hash Function
A one-way fingerprint that turns any input into a fixed-size digest, where flipping one input bit scrambles roughly half the output.
Hash Function
A cryptographic hash function crushes an input of any size — a word, a file, a movie — into a short, fixed-length digest (a "fingerprint"), in a way that is easy to compute but impossible to reverse or fool. SHA-256, for instance, maps anything to exactly 256 bits. It is the workhorse of modern cryptography: it backs Digital Signatures, password storage, blockchains, and integrity checks everywhere.
A good hash h = H(m) must satisfy three properties:
- Pre-image resistance — given a digest h, you cannot find any m with H(m) = h (one-way).
- Second pre-image resistance — given m, you cannot find a different m' with the same digest.
- Collision resistance — you cannot find any two inputs that hash to the same value.
The avalanche effect
The property that makes a fingerprint trustworthy is the avalanche effect: change the input by a single bit and about half of the output bits flip, with no visible pattern. The digest of hello and the digest of hellp should look completely unrelated. Measured with Hamming Distance — the number of differing bits — a one-bit input nudge should land you roughly halfway across the entire output space.
Notice the digest stays near 50% flipped no matter which inputs you roll. That near-total decorrelation, viewed through Entropy, is what makes a digest behave like a random draw and lets it stand in for the message itself.
Where hashes earn their keep
The avalanche and one-wayness combine into a few indispensable jobs:
- Integrity. Publish a file's digest; a single altered byte avalanches the hash, exposing tampering instantly.
- Signatures. Public-key signing is slow, so you sign the short hash of a message rather than the whole thing — the heart of a Digital Signature.
- Passwords. Store H(\text{password}), never the password. A breach leaks digests, and one-wayness keeps the originals hidden.
- Commitments and blockchains. Hash-link records so any change to history breaks every fingerprint downstream.