10 Codes and Ciphers
The need to conceal the meaning of important messages has existed for thousands of years. Over time, people have found increasingly complex ways of encoding their messages as the simpler ways are decoded with greater ease. Contrary to layman-speak, codes and ciphers are not synonymous. A code is where each word in a message is replaced with a code word or symbol, whereas a cipher is where each letter in a message is replaced with a cipher letter or symbol. In fact, when most people say “code,” they are actually referring to ciphers. Ancient scripts and languages have been understood using decoding and deciphering techniques, most famously the Rosetta Stone of Ancient Egypt. In fact, codes and ciphers have determined the outcome of politics and wars throughout history. There are thousands of types of hidden messages, but here we look at only ten as an overview. Several have examples for you to test yourself with.
Steganography is more ancient than codes and ciphers, and is the art of hidden writing. For example, a message might be written on paper, coated with wax, and swallowed to conceal it, only to be regurgitated later. Another way is to tattoo the message on the shaved head of a messenger and wait for the hair to regrow to cover up the ink. The best stenography uses innocent everyday objects to carry messages. A once-popular technique in England was to use a newspaper with tiny dots under letters on the front page indicating which ones should be read to spell out the message. Some people would spell out a message using the first letter of every word, or use invisible ink. Rival countries have shrunk writing down so that an entire page of text becomes the size of a pixel which is easily missed by prying eyes. Steganography is best used in conjunction with a code or cipher, as a hidden message always carries the risk of being found.
This is a cipher familiar to many children. Its key is simple: each letter of the alphabet is replaced with the following letter, so A is replaced with B, B is replaced with C, and so on. “ROT1” literally means “rotate 1 letter forward through the alphabet.” The message “I know what you did last summer” would become “J lopx xibu zpv eje mbtu tvnnfs” and so on. This cipher is fun because it is easy to understand and use, but it is equally easy to decipher if they key is used in reverse. This cipher is not suitable for serious use but can be of great amusement for children. Try to decipher the message “XBT JU B DBU J TBX?”
In transposition ciphers, the letters are rearranged according to some predetermined rule or key. For example, words might be written backwards, so that “all the better to see you with” becomes “lla eht retteb to ees joy htiw.” Another transposition key is to swap every pair of letters, so the previous message becomes “la tl eh eb tt re to es ye uo iw ht.” Such ciphers were used during the First World War and the American Civil War to send sensitive messages. Complex rules of rearrangement can make these ciphers seem very difficult at first, but many transposed messages can be deciphered using anagrams or modern computer algorithms which test thousands of possible transposition keys. To test yourself, try to decipher: THGINYMROTSDNAKRADASAWTI.
Despite its name, Morse code is not a code but a cipher. Each letter of the alphabet, the digits 0-9, and certain punctuation symbols, are replaced by a sequence of short and long beeps, often called “dots and dashes.” A becomes “•-”, B becomes “-•••” and so on. Unlike most other ciphers, it is not used to conceal messages. Morse code was of great use with the invention of Samuel Morse’s telegraph, which was the first widely-used electric means of sending messages long-distance. It involved laying a long wire between places and running an electric current down the wire. The electric current could be detected by a receiver many kilometers away, and dots and dashes were simulated by turning the current on and off. The telegraph revolutionized media, allowing events in one country to be immediately reported in another, and it changed the nature of warfare by allowing instantaneous communication with troops a long distance away. •–• •- •-• •- -••• • •-•• •-•• ••- –
The Caesar shift cipher, named because it was used by Julius Caesar himself, is actually 26 different ciphers, one for each letter of the alphabet. ROT1 is just one of these ciphers. A person only needs to be told which Caesar cipher was used in order to decipher a message. If the G cipher is used, then A becomes G, B becomes H, C becomes I, and so on through the alphabet. If the Y cipher is used, then A becomes Y, B becomes Z, C becomes A, and so on. This cipher is the basis for many more complex ciphers, but on its own does not allow great protection of a secret message, as checking 26 different cipher keys does not take a relatively great amount of time. Li bra ghflskhu wklv dqg bra nqrz lw, fods brxu kdqgv.
ROT1, Caesar shift, and Morse code are all of the same type: mono alphabetic substitution, meaning that each letter of the alphabet is replaced according to the key with another letter or symbol. Without knowing the key, these are actually easy to decipher. The most common letter in English is well-known to be E. Therefore, in any mono alphabetic cipher, the most common letter or symbol will also be E. The second most common English letter is T, and the third most common is A, and so these two letters can also be determined. From this point, a person deciphering a message can continue using the frequencies of English letters or they can look for nearly-complete words, such as “T_E” which is most likely “THE.” Unfortunately, this only works for long messages, and not on ones with only a few words, since they do not have enough letters to show which are the most frequent. Mary Queen of Scots famously used a mono alphabetic cipher with several variations that was incredibly difficult, however when it was finally broken, the messages therein gave the evidence needed by her enemies to sentence her to death. Ptbndcb ymdptmq bnw yew, bnwzw raw rkbcriie wrze bd owktxnwa.
This cipher is more complex than mono alphabetic substitution. Its key is a word, such as “CHAIR.” The rule of the cipher is similar to that of the Caesar shift cipher, except it changes with every letter according to the keyword. The first letter of a message with key word CHAIR would be encoded with the C cipher alphabet, the second with the H cipher alphabet, and it continues like this through the keyword. The keyword is only five letters long, so for the sixth letter of the message a C cipher is used again. The Vigenère cipher was thought to be unbreakable for a long time. To decipher, first the length of the keyword is guessed. If the keyword is guessed to be five letters long, then letters numbered 1, 6, 11, 16, 21, etc. will all correspond to the first letter of the keyword, and letter frequency analysis will decipher them. The decoder then moves to letters 2, 7, 12, 17, and so on. If the keyword is indeed five letters long, this will decode the cipher. If not, another keyword length must be guessed and the process repeated. Eoaqiu hs net hs byg lym tcu smv dot vfv h petrel tw jka.
In a true code, each word is replaced by a code word or number according to a key. Since there are many words that might be in the message, the key is usually a code book where someone can look up an English word and find the corresponding code word, not unlike a dictionary. Just as short messages are difficult to decipher with letter frequency analysis, a code needs to be extraordinarily long before word frequency analysis becomes useful, so codes are harder to decode than ciphers. Many countries have used variants of codes, where each day a new code was used to keep them safe from word frequency analysis. For everyday life, however, codes are slow and making a code book is cumbersome. Worse, if the code book is stolen, then the code is no longer safe and a new one must be made, taking a tremendous amount of time and effort. Codes are mainly useful to the rich and powerful who can delegate this work to others.
The Enigma code, which was a very sophisticated cipher, was used during the Second World War by the Germans. It involved an Enigma machine, similar to a typewriter, where pressing a letter would make the cipher letter light up on a screen. The Enigma machine involved several wheels which connected letters with wires, determining which cipher letter would light up. All Enigma machines were identical, and knowing the initial configuration of the wheels inside was the key to enciphering messages. To make things harder, each wheel would rotate after a certain number of letters were typed, so the cipher was continuously changing within a message. German commanders had Enigma machines and would be issued lists of the initial wheel configuration to use for each day so that all the Germans used the same one and could decipher each other’s messages. Even when the Allies procured a copy of the Enigma machine they could not decipher anything, as there were over one hundred trillion possible wheel configurations to check. The Enigma code was broken by Polish ingenuity and perfected by the British using geniuses and computers. Knowledge of the German communications gave the Allies a vital advantage in the War, and from breaking the Enigma code, the ancestor of modern computers was born.
This is the ultimate modern cipher, and it has several variants. This cipher, used world-wide, has two keys: one public and one private. The public key is a large number available to everyone. The number is special in that only two whole numbers (apart from 1 and the number itself) will divide into it perfectly. These two numbers are the private key, and if multiplied together, produce the public key. So the public key might be 1961, and the private key 37 and 53. The public key is used to encipher a message, but it is impossible to decipher without the private key. When you email personal details to a bank, or when your bank card is read by a machine, the details are enciphered this way and only the bank can access them with their private key. The reason this is so secure is that mathematically it is very difficult to find divisors of large numbers. To help security, until recently RSA Laboratories gave money to anyone who could find the two divisors of the numbers they gave. For a relatively easy example, once worth $1000 USD, try to find the two 50-digit divisors of 1522605027922533360535618378132637429718068114961