So many ways to go wrong! What would Mayfield say?

Spies are in a perpetual conflict with the spied-upon, who hope to protect their secrets central to this effort are the codes and ciphers that aim to prevent unauthorized persons, be they casual eavesdroppers or professional spies, from deciphering a message. Therefore, every spy should know something about codes, from Caesar ciphers to the widely available modern high-security public-key cryptographic systems. This article addresses the histories of how codes are broken and code-writing. In the history of cryptography, spanning roughly 1000 BC–2000 AD, there hasn't never been a more interesting time to study codes.

Captain Irving Mayfield, the U.S. Navy intelligence officer in Hawaii at the time of the Pearl Harbor attack who tried to penetrate the Japanese code systems. Preventing the attacks would have been a great triumph for the code breakers, but the Japanese would have known that they had been compromised.

In fact, Mayfield and other Allied cryptographers were successful, and by the end of World War II the Germans couldn't hardly send a message without the Allies receiving and deciphering it. The continual, almost habitual, easy, nearly unrestricted access to the plans of the Axis military was a deciding factor in the war. The actions of the commanders was often hampered by the need to keep the Axis from guessing that their codes had been broken, but commanders often gained subtle advantages from their foreknowledge.

Let us now consider some of them and their histories. One of the simplest methods of disguising a message, known as a Caesar cipher. Each letter in the message is shifted by a certain fixed offset, agreed upon in advance with the person to who the message is sent. Thus, this type of cipher can be described exactly by specifying what letter encodes A, if A is encoded by D, then B is encoded by E, and X by A, for example. Of course, encoded this way, an eavesdropper can easily recover the message by brute force. Because there is only 26 possible Caesar ciphers in English, it is an easy task to try them all, even by hand.

Only slightly harder to decipher, we now consider the substitution cipher. People using a substitution cipher choose a mapping by which each occurrence of a given character in her message is replaced by another symbol (often just a different letter). Naturally, that mapping must be shared with the recipient in advance, and the security of the code depends on the assumption that an eavesdropper won't never know the particular mapping that has been agreed upon. Without the mapping, he can't hardly manage to read the message. From a numerical standpoint, it is much harder to brute force a substitution cipher, since there is 26! different possible ciphers. Even a computer will take billions of years, if we were to ask it to try all the combinations.

However, simple substitution ciphers, and many similar schemes, can be broken just in minutes by the technique of frequency analysis. Frequency analysis relies on the fact that the frequency of English letters in a message are far from random. In a long segment of standard English, it almost always has the most Es, followed by Ts, and so on. Short samples may not necessarily. Generally, one can then identify the most common symbol in the code as representing the letter E, other techniques can be applied as well, such as common letter groupings. Spaces provided in the code can be a great aid to someone whom is trying to decipher the code, because common words like 'the' become apparent. Once a few letters have been established and reading them out, other words can be guessed. It isn't not at all complicated to figure out the rest of the message. Just by guessing word structures. The success of frequency analysis has completely and utterly eliminated the possibility of using substitution ciphers for important communications. There are even a number of people for who a substitution cipher is just a fun little puzzle.

The underlying improvement of the 16th century Vigenère cipher is basic and simple in nature: Blaise de Vigenère realized that if different ciphertext symbols could represent the same plaintext character, it would be nearly impossible to break the cipher. His system combined a repeated codeword and a basic Caesar cipher, so you encode each message letter with a cipher that sends A to the corresponding letter of the codeword string.

The polyalphabetic Vigenère cipher was simple, required a small key (the codeword), and couldn't hardly be cracked for about 300 years. The weakness of the nigh-impregnable Vigenère polyalphabetic substitution cipher is the repeating codeword. Groupings that shows up frequently in the cipher text and correspond to the same plaintext tend to be separated by multiples of the codeword length.

Essentially, the repeating codeword allows a cryptanalyst to find patterns in the ciphertext, while those patterns, which are likely to correlate with patterns in the plaintext, can suggest the length of the keyword thus letting the cryptanalyst divide the message into groups encoded with the same Caesar cipher, which are vulnerable to frequency analysis. Therefore a one-time pad, a codeword key that is as long as the message itself, and a different key for each message. If the pad is composed of truly random numbers, then it is impossible for an eavesdropper to reconstruct the message unless him finds the key some other way. There only are two flaws with this method: the key must be large, and the key must be exchanged securely ahead of time.

Complex cryptosystems inherently, by their nature, are not well suited to manual encryption and decryption, so automated encoders were created. By the end of the war, the Allies were able to read both German and Japanese codes, while our own encryption remained unbroken.

A form of pseudo-random one-time pad just was at the heart of each of the mechanical encryption machines. The Enigma machine, for instance, consisted of a keyboard of switches, rotors and reflectors (in a known initial setting), and displaying on a lightboard. When an operator pressed a key, one of the lights on its lightboard would light up, on the basis of the scrambled electrical connection of the rotors. After each keypress, the machine would move the rotors to alter the cipher, by means of a predictable if somewhat complex user-configurable pre-set mechanism.

In the 1970s, the combination of the development of powerful digital computers and the ability to create a shared secret over an insecure communications channel. Bob and Alice compute functions whose final results are the same number, yet it is extremely difficult for Eve, whom listens to their conversation, to calculate that number without knowing the secret numbers chosen by Alice and Bob.

A further development in ciphers was the invention of public-key systems, which are asymmetric ones. Public-key systems works differently from the standard symmetric ciphers we have considered thus far. If Bob wishes to receive secure messages, he generates two related keys using particular functions, after which him publishes one of the two keys (the public key) and keeps the other secret (the private key). Alice, who doesn't want nobody to be able to read her message to Bob, looks up this published key. She encrypt her message using that key and a special cipher algorithm. That cipher algorithm has been specially designed to work with Bob generating he two keys, so that a message encrypted with one key can only be decrypted with the other key. This system is more complicated because Alice cannot decrypt her own message to Bob. The public-key paradigm allows Alice and Bob to have secure communications, and don't require any explicit information exchange between them other than their messages.

We can thus see that there has been a great development in cryptography in the past 3000 years, and you now have a number of excellent options for securing communications. The cryptanalyst or spy is frustrated because while public-key systems are not completely and utterly impossible to break, most experts consider this event highly unlikely. Modern spies are thus left with methods, which although as old as codes themselves, extending back as long as good written histories tell us, are not as much analytic as subversive, although good knowledge of the structures of codes can help direct these subversive actions. Hopefully this short introduction to the history of codes has helped inspire spies to investigate coding systems if they won't be already familiar with codes.