Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Hashes, Keys and Signatures  ›  Lesson

Hash Functions — Fingerprints for Data

Cryptography & Hashing 12 minA cryptographic hash function turns any input into a fixed-size fingerprint that is deterministic, changes completely with any edit, and cannot practically be reversed.

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") = 245847cc211a5555290467fb275551853ae46e26dd13b260c35c80acd5b899e6

One digit changed in the input, and the two outputs share no visible pattern. Five properties make hashes useful:

  1. Deterministic. The same input always gives the same hash, on any computer, at any time.
  2. Fixed size. A 16-character message and an 18,000-character file both produce 64 hex characters.
  3. Avalanche effect. A tiny change to the input scrambles the whole output.
  4. 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.
  5. 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?"

Which property protects the co-op chain?Step 1 of 4
  1. 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.

quick drill

How long is a SHA-256 hash written in hexadecimal?

quick drill

You hash "Asha pays Ravi 5" today, then again next year on a different computer. What do you get?

quick drill

"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?

quick drill

Someone publishes only the SHA-256 hash of a secret sentence. What can you do with it?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhich property does the work?

Explain which properties of a hash function let every co-op node detect Ravi's edit to an old block, and explain why a hash is not the same thing as encryption.