Lesson 4 of 4 · Open
Secret writing: encryption
How a message stays secret even though it passes through strangers' hands.
A message to your bank travels in packets through many routers that belong to strangers. Whoever runs one of them could look inside. A code alone does not protect it: traffic light colors and Morse code are open to everyone, and anyone who knows the code table can read along. How does a message stay secret even though it passes through strangers' hands?
The answer is to encrypt it: the readable message, the plaintext, is turned into a ciphertext that looks unreadable, using a secret key. Only someone who knows the key can decrypt the ciphertext, that is, turn it back into the plaintext.
New terms
- plaintext
- the readable message before it is encrypted
- ciphertext
- the encrypted message, unreadable without the key
- key
- the secret that sets how the encryption works, such as a number
- encrypt
- to turn the plaintext into a ciphertext using the key
- decrypt
- to turn the ciphertext back into the plaintext using the key
The shift
A very old method is said to have been used by Julius Caesar: each letter is moved forward a fixed number of places in the alphabet. This number is the key. With key 3, A becomes D, B becomes E, and C becomes F. After Z, it continues at A again: X becomes A, Y becomes B, Z becomes C.
| Plaintext | Ciphertext, key 3 |
|---|---|
| A B C D E | D E F G H |
| F G H I J | I J K L M |
| K L M N O | N O P Q R |
| P Q R S T | S T U V W |
| U V W X Y Z | X Y Z A B C |
Example
HELLO with key 3
Each letter moves three places forward. That gives the ciphertext, and with the same key the plaintext comes back.
- H becomes K
- E becomes H
- L becomes O, twice
- O becomes R
- Ciphertext: KHOOR
To decrypt, you go the same way back: each letter moves back by the key, toward A. Before A, it continues at Z at the end. So with key 3, the ciphertext letter A turns back into an X.
Quick check
Key 3: what does Y become when you encrypt?
How safe is the shift?
Someone who does not know the key can guess it. There are only 25 useful keys, from 1 to 25. A shift by 26 takes each letter once through the whole alphabet and back to its place, so the ciphertext would be the plaintext. A larger key works like a smaller one: 27 like 1, 28 like 2.
Example
Trying every key
Someone intercepted the ciphertext YFCN. Without the key, they move all the letters back by 1, 2, 3, and so on, one key after another:
- Key 1: XEBM
- Key 2: WDAL
- Key 3: VCZK
- Key 4: UBYJ
- Key 5: TAXI, a real word. The key has been found.
With pencil and paper, this takes a few minutes. A computer tries all 25 keys in a tiny fraction of a second. So the shift only keeps out people who do not even try.
How encryption works today
The small lock in the browser shows that the connection is encrypted, also called HTTPS. Today's methods do not shift letters, they calculate with numbers, since the data is made of bits anyway. Exactly how is simplified here. The key is a bit sequence of 128 bits or more.
Each bit doubles the number of possible keys. With 128 bits, that is a number with 39 digits. Even all the computers in the world together could not try that many keys in millions of years. The addresses on the packets stay readable, or no router could forward them. What gets encrypted is the contents.
Typical mistake
Mistaking a code for encryption, for example thinking a message in Morse code is secret. That cannot be right: the code table is open to everyone, and anyone can look it up and read along. A message only becomes secret through a key that only the sender and the recipient know.
Remember
Tasks
Task 1 · Pairs
Which term means what?
Task 2 · Input
The plaintext SOFA becomes the ciphertext ZVMH. Which key was used?
Task 3 · Choice
PIZZA is encrypted with key 4. Which ciphertext comes out?
Go deeper
Task 4 · Sorting · optional
Code or encryption? Sort each row.
6 cards left
Task 5 · Several right · optional
An encrypted message travels in packets through strangers' routers. What can a router read?
Task 6 · Input · optional