Background reading · Mathematics and Statistics
Secret codes: from Caesar to your phone
How ciphers work, how patterns give them away, and how prime numbers protect messages on the internet today.
For as long as people have written messages, other people have wanted to read them. So people invented codes. The science of making and breaking codes is called cryptography.
The Caesar shift
Julius Caesar, a Roman leader, is said to have sent messages with every letter shifted three places along the alphabet: A became D, B became E, and so on. To read it, you shift back three. A cipher wheel, two paper circles joined in the middle, makes this quick to do.
How patterns give codes away
A Caesar cipher has a weakness: there are only 25 shifts to try. There is a smarter trick too. In English, E is the most common letter, then T and A. Count the letters in a long coded message. The most common one is probably E, which tells you the shift. This is called frequency analysis, and it was described by the Arab scholar Al-Kindi more than 1,000 years ago.
Machines and codebreakers
During the Second World War, the German military used the Enigma machine. Its rotating wheels changed the cipher with every key press, giving millions of millions of possible settings. At Bletchley Park in England, a team including mathematician Alan Turing looked for patterns and built machines to test settings quickly. Cracking Enigma is thought to have shortened the war.
Codes in your pocket
Today, messages, bank details and passwords travel across the internet in code. Many systems use prime numbers. A computer multiplies two enormous primes together to make a lock that anyone can use to send a secret. Only the person who knows the two original primes can open it. Multiplying is fast, but finding the two primes from the answer would take even a supercomputer an extremely long time. That is why strong passwords, and never sharing them, still matter.
Sources and further reading
- Public key encryption (CS Unplugged, University of Canterbury) ↗
- CS Unplugged topics (University of Canterbury) ↗
- Bletchley Park ↗
Written for Kōkiri Learn students in our own words. Check facts against the sources.