Symmetric encryption

One key between two identical, mirrored padlocks that both open towards it.

Julius Caesar wrote his letters to his generals in secret writing: every letter shifted a few places forward in the alphabet. A becomes D, B becomes E. Whoever knew how many places could read it. Whoever didn't, saw nonsense. That "how many places" is the key — and two thousand years later, that idea is still the basis of how your messages get secured.

Words you might need

Key
The secret you need to encrypt and decrypt. For Caesar, a number from 1 to 25. For modern systems, a string of 256 random bits. Whoever has the key can read it. Whoever doesn't, can't.
Symmetric
The same key locks and unlocks. Like the key to your bike lock: one key, and you have to share it with anyone allowed to open the lock.
Plaintext and ciphertext
Plaintext is your ordinary message. Ciphertext is what comes out after encrypting it: just noise to anyone without the key.
AES
The secret-writing system almost everything uses today: your wifi, your messages, your banking app. The world standard since 2001, and in all those years no one has found a hole in it.
IV (initialisation vector)
A random number that's different for every message, so that the same message sent twice with the same key still produces two different ciphertexts. Otherwise someone eavesdropping would see: "hey, he sent that same message yesterday too".

What's changed in 2000 years

Caesar had 25 possible keys. You can try them all by hand in fifteen minutes. AES has 2256 possible keys. Put every computer on Earth to work together, and they'll still be at it when the sun burns out. The principle is the same; only the math under the hood is incomparably smarter.

Something else has been added too. Caesar couldn't tell if someone had changed a letter along the way. Modern encryption can: AES in GCM mode attaches a kind of wax seal to the message. If even a single bit of the ciphertext gets changed, the seal breaks and it refuses to decrypt. You're about to see that happen yourself.

Try it yourself

Everything happens in your browser. Nothing is sent to the server.

  1. Click Encrypt. The encrypted package appears in the box below — unreadable.
  2. Click Decrypt. Your message comes back.
  3. Now change one letter in the password and click Decrypt again. No message, just a refusal.
  4. Put the password back. Click Flip one bit — the demo changes a single 0 into a 1 in the package. Click Decrypt. The seal is broken.
  5. Encrypt the same message twice. Compare the two packages.

In step 5 you saw two completely different packages for the same message. That's the IV at work. And it matters: someone eavesdropping on your traffic shouldn't even be able to tell that you sent the same thing twice.

The problem Caesar already had

Everything above only works if you and the recipient have the same key. Caesar could whisper the key to his general before he left. But how do you do that with a website in America you've never met? You can't just send the key along — then the eavesdropper reads it too and it's all for nothing.

This is called the key exchange problem, and it seemed unsolvable for centuries. Until in 1976 two mathematicians came up with something that sounds like a magic trick. That's the next chapter.

This is math: clock arithmetic

Caesar adds 3 to every letter. But what comes after Z? You start over at A. That's arithmetic on a clock with 26 hours: 25 + 3 = 2. Mathematicians call that modulo 26. It sounds like a trick for kids, but it's the building block of all modern cryptography. Every chapter after this one uses it — on a clock with a circumference given by a number with 78 digits.