Grade 10 Computer Science · Encryption and trust

An operation easy to do and hard to reverse

The gap all encryption rests on.

A secret that passes through strangers’ devices

Every message you send passes through a chain of devices that are not yours, and none of them promises not to look. And still a secret can be sent that way. The answer is not in the route itself, but in one idea that needs no formula at all. What is it?

In grade eight you learned that the internet passes information through a chain of devices that are not yours. The question left open is how something secret can nonetheless be sent along such a route. The answer is not in the route — it is in one mathematical idea, which can be understood with no formula at all.

The gap between the easy direction and the hard one is the whole basis.
import hashlib

text = "the quick brown fox"
digest = hashlib.sha256(text.encode()).hexdigest()
print(digest[:16])       # a fixed-length fingerprint

# changing one letter changes the whole fingerprint
other = hashlib.sha256("the quick brown fix".encode()).hexdigest()
print(digest[:16], other[:16])

A fingerprint and not encryption

The operation in the example is called hashing, and it is important not to confuse it with encryption. Encryption is meant to be opened again by whoever has a key; hashing is not meant to be opened at all, not even by you. It produces a fixed-length number from any input, such that changing one letter replaces the entire result. So it is a tool for checking whether something changed — and not a tool for hiding content.

The toolMeant for…Opens again
HashingChecking whether something changedNo
EncryptionHiding contentWith a key

Example 1 — why one letter changes everything

  1. The operation mixes the whole input.
  2. Every bit affects the whole result.
  3. So a small change is seen at once.

Example 2 — why “not worthwhile” suffices

  1. Breaking is possible in principle.
  2. It needs more time than exists.
  3. So no one tries.
A fingerprint has a fixed length, so there are collisions — the whole protection is that finding them on purpose costs too much.