FOUR
The Case of the Uncrackable Code
Ever since people first learnt to communicate, theyâve been finding ever more fiendish ways to hide messages from their enemies. Maybe you used a private code to write your diary so that your brother or sister couldnât read it, just as Leonardo da Vinci did. But codes arenât only for keeping things secret: they also make sure that information is communicated without errors. And we can use mathematics to create ingenious ways to guarantee that the message that is received is the same as the message that was sentâwhich is vitally important in this age of electronic transactions.
A code is simply a systematic way of arranging a set of symbols to convey a particular meaning. As soon as you start looking for them, you discover that codes are all around us: there are barcodes on everything we buy; codes enable us to store music in our MP3 players; codes let us browse the Internet. Even this book is written in codeâEnglish is simply a code formed of the 26 letters of the alphabet, and our âacceptable codewordsâ are stored in the Oxford English Dictionary. Even our body contains codesâDNA is a code for reproducing a living creature made of four organic chemical substances called bases: adenine, guanine, cytosine and thymine, or A, G, C and T for short.
In this chapter Iâll show you how mathematics has been used to create and break some of the cleverest codes around, and how it lets us transmit information safely, efficiently and secretly, and lets us do everything from photographing the planets from spacecraft to shopping on eBay. And at the end of the chapter Iâll explain how cracking one of the million-dollar maths problems could help you to crack codes as well.
How to use an egg to send a secret message
In Italy in the sixteenth century, Giovanni Porta discovered that you could write a hidden message on a hard-boiled egg with an ink made by dissolving an ounce of alum in a pint of vinegar. The ink penetrates the shell and marks the hardened white inside, but while the writing stays on the egg white, it disappears from the shell. Perfect for sending secret messagesâto crack the code, you crack the egg! And this is just one of the many crazy ways people have come up with to hide secret messages.
In 499BC a tyrant by the name of Histiaeus wanted to send a secret message to his nephew Aristagoras encouraging him to rebel against the Persian king. Histiaeus was stationed in Susa, in modern-day Iran, and his nephew was back home in Miletus, now a part of Turkey. How could he get a message to his nephew without the Persian authorities intercepting it? He came up with a cunning plan. He shaved the head of his faithful servant and tattooed the message onto his bald head. Once the hair had grown back, Histiaeus sent the servant off to find his nephew. When the servant reached Miletus, the nephew shaved the servantâs head, read the message and began a rebellion against the ruling Persian king.
While the nephew only had to shave the messengerâs head to retrieve the message, we have to pity the recipients of secret messages sent by an Ancient Chinese method. The message would be written on a piece of silk, which was then rolled up very tightly. The silk ball was covered in wax and given to the messenger to swallow. Recovering the message once it had reappeared was not a particularly pleasant affair.
One of the most sophisticated ways of hiding a message was developed by the Spartans in 500BC. They used a special wooden cylinder called a scytale around which they would wrap a thin strip of paper in a spiral. The secret message would then be written on the paper, lengthways down the scytale, but when the paper was unwrapped the message looked like gobbledygook. It was only by winding the strip of paper round another scytale of exactly the same dimensions that all the letters lined up again correctly.
These methods for sending secret messages are examples of steganographyâthe art of concealingârather than coding. But however devious they were, once the message was discovered the secret was out. So people started thinking about how to conceal the meaning of the message even if it was uncovered.
How to crack the Kama Sutra codes by counting
B OBDFSOBDLNLBC, ILXS B QBLCDSV MV B QMSD, LE B OBXSV MH QBDDSVCE.
LH FLE QBDDSVCE BVS OMVS QSVOBCSCD DFBC DFSLVE, LD LE ASNBGES DFSJ BVS OBTS ZLDF LTSBE. DFS OBDFSOBDLNLBCâE QBDDSVCE, ILXS DFS QBLCDSVâE MV DFS QMSDâE OGED AS ASBGDLHGI; DFS LTSBE ILXS DFS NMIMGVE MV DFS ZMVTE, OGED HLD DMUSDFSV LC B FBVOMCLMGE ZBJ. ASBGDJ LE DFS HLVED DSED: DFSVS LE CM QSVOBCSCD QIBNS LC DFS ZMVIT HMV GUIJ OBDFSOBDLNE.
This looks like gibberish, but itâs a message written using one of the most popular codes ever created. Called the substitution cipher, it works by switching every letter of the alphabet with another one: so a might become P, t might become C, and so on. (Iâve used lower-case for letters in the unencrypted messageâthe plaintext, as itâs known in the trade, and capitals for letters in the ciphertext.) As long as the sender and receiver have agreed the substitution key in advance, the receiver will be able to decipher the messages, but to everyone else theyâll be a meaningless string of nonsense.
The simplest version of these codes are called Caesar shiftsâafter Julius Caesar, who used them to communicate with his generals during the Gallic Wars. They work by shifting each letter the same number of places along. So with a shift of three, a becomes D, b becomes E, and so on. From the Number Mysteries website you can download and cut out your own cipher wheel for creating these simple Caesar shifts.
Shifting each letter by the same number of places gives you only 25 possible ciphers, so once youâve spotted that this is how the message has been encoded itâs quite easy to unscramble. Thereâs a better way to encode a message: instead of simply shifting all the letters along together, we can mix things up and allow any letter to be substituted for any other. This method of encrypting messages was actually suggested some centuries before Julius Caesar, and surprisingly it wasnât in a military handbook but in the Kama Sutra. Although this ancient Sanskrit text is usually associated with a description of physical pleasures, it covers a host of other arts that the author believed a woman should be versed in, from conjuring and chess to bookbinding and even carpentry. The 45th chapter is dedicated to the art of secret writing, and here the substitution cipher is explained as a perfect way of concealing messages detailing liaisons between lovers.
While there are only 25 Caesar shifts, if we allow ourselves to substitute any letter for any other then the number of possible ciphers is somewhat greater. We have 26 choices for what to change the letter a into, and for each of those possibilities there are 25 choices of where to send the letter b. (One letter has already been used to encrypt the letter a.) So there are already 26x25 different ways to scramble the letters a and b. If we keep going, choosing different letters for the rest of the alphabet, we find that there are
26x25x24x23x22x21x20x19x18x17x16x16x15x14x13x12x
11x10x9x8x7x6x5x4x3x2x1
different Kama Sutra codes. As we saw on page 40, we can write this as 26!. We should also remember to take 1 off this number because one choice will have been A for a, B for b through to Z for z, which isnât much of a code. When we multiply out 26! and take away 1 we arrive at the grand total of
403,291,461,126,605,635,583,999,999
different ciphersâover four hundred million billion billion possibilities.
The passage at the beginning of this section is encrypted with one of those codes. To give you an idea of how many possible permutations there are, if I wrote out the passage using all the different possible codes, then the piece of paper would stretch from here to well beyond the outskirts of our Milky Way galaxy. A computer checking one code a second since the Big Bang went off over 13 billion years ago would still be just a fraction of the way through checking each of the codesâand a very small fraction at that.
So the code looks virtually uncrackable. How on earth (or beyond) can you find out which one of this vast number of possible codes Iâve used to encrypt my message? Amazingly, the way to do it is by a very simple bit of mathematics: counting.
It was the Arabs in the time of the Abbasid dynasty who first developed cryptanalysis, as the science of codebreaking is called. The ninth-century polymath Yaâqub al-Kindi recognized that in a piece of written text some letters crop up again and again, while others are used rarely, as shown above. This is something that Scrabble players are well aware of: the letter E is worth only 1 point, as it is the most common letter in the English alphabet, while a Z is worth 10 points. In written texts every letter has its own distinct âpersonalityââhow often it appears, and in what combinations with othersâbut the key to al-Kindiâs analysis is to realize that a letterâs personality doesnât change when it is represented by another symbol.
So letâs make a start at cracking the code used to encrypt the text at the beginning of this section. Table 4.02 contains a breakdown of the frequency of each of the letters used in the encrypted text.
From the table we can see that the letter S occurs with a frequency of 13%, more than any other letter in the ciphertext, so thereâs a good chance that this letter is the one used to encode the letter e. (Of course, you have to hope that I havenât chosen a passage from Georges Perecâs novel A Void, which was written without using the letter âeâ anywhere in the text.) The next most common letter in the ciphertext is D, with a frequency of 12%. The second most common letter in the English language is t, so this would be a good guess for the choice of D. Third in order of frequency in the encrypted message is B, which is used 10% o...