Hash Functions — Fingerprints for Data
In section 1, Ravi's edit to an old block was caught because the block's fingerprint changed. That fingerprint is a hash, and almost every part of a blockchain leans on it: block links, transaction IDs, mining and addresses. This lesson makes the idea precise.
The rule
Same input, same hash; change one bit, change everything; never run it backwards.
A cryptographic hash function takes input of any size and returns an output of fixed size. Bitcoin uses SHA-256, whose output is 256 bits, usually written as 64 hexadecimal characters. Ethereum uses a different function, Keccak-256, which is also 256 bits long.
SHA-256("Asha pays Ravi 5") = ef4f6f0fea431f4b4dd3b1e9f0c88c5dc028a807ede25da5ab3efb7e9e80245e
SHA-256("Asha pays Ravi 6") = 245847cc211a5555290467fb275551853ae46e26dd13b260c35c80acd5b899e6One digit changed in the input, and the two outputs share no visible pattern. Five properties make hashes useful:
- Deterministic. The same input always gives the same hash, on any computer, at any time.
- Fixed size. A 16-character message and an 18,000-character file both produce 64 hex characters.
- Avalanche effect. A tiny change to the input scrambles the whole output.
- One-way. Given a hash, there is no practical way to find an input that produces it, other than guessing inputs one at a time.
- Collision resistant. Nobody can practically find two different inputs with the same hash.
Collisions must exist in principle, because there are endlessly many possible inputs and only 2²⁵⁶ possible outputs. But finding one for SHA-256 is far beyond any computer that exists.
A hash is not encryption. Encryption is built to be reversed by whoever holds the key. A hash has no key and is built never to be reversed.
The shortcut
For any blockchain question that involves hashes, ask "which property is doing the work here?"
Linking blocks
Each block stores the previous block's hash, and every node recomputes it and gets the same value. Deterministic.
The trap is thinking that "hashed" means "hidden, but recoverable with a password", or that similar inputs give similar hashes. Neither is true.
Drills
Answer fast — trust the rule.
How long is a SHA-256 hash written in hexadecimal?
You hash "Asha pays Ravi 5" today, then again next year on a different computer. What do you get?
"asha pays Ravi 5" differs from "Asha pays Ravi 5" only in the case of the first letter. How similar are their SHA-256 hashes?
Someone publishes only the SHA-256 hash of a secret sentence. What can you do with it?
Why must collisions exist for SHA-256, even though nobody can find one?
Remember
- Same input, same hash; change one bit, change everything; never run it backwards.
- Shortcut: name the property doing the work: deterministic, fixed size, avalanche, one-way, collision resistant.
- Trap: hashing is not encryption. No key turns a hash back into its input.
