Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

People have used mechanical devices to help with enciphering since ancient times. The scytale, a rod that a strip of writing was wound around, is mentioned by the Greek poet Archilochus in the 7th century BC. Alberti’s cipher disk from the 1460s (Section 7.1) was a mechanical way to switch cipher alphabets.

The attacks in this chapter all depend on a keyword that repeats. The Kasiski test finds repeated pieces of ciphertext, and the index of coincidence finds the period. In the 20th century, cryptographers answered with machines. At their core, most of them are not very different from the Vigenère cipher: each letter is shifted or substituted using a keystream. The difference is that a machine builds the keystream with wheels, pins and rotors, instead of repeating a keyword or using a primer and the plaintext. That makes the keystream very long and hard to predict, so there is no short repeating keyword for the Kasiski test or the index of coincidence to find. It also makes enciphering fast.

The Hagelin Machines

Boris Hagelin (1892 to 1983) was a Swedish businessman and inventor of purely mechanical cipher machines (no electricity). He took over the Swedish company AB Cryptograph in 1925 and renamed it AB Cryptoteknik in 1932. His machines, including the C-36, the C-38 and later the C-52, sold by the tens of thousands.

The C-36

To encipher a letter on the C-36, the operator sets the plaintext letter on a dial and turns a lever. A printing wheel prints the ciphertext letter on a paper tape. Inside, two parts decide how far the printing wheel turns:

  • Five pin wheels, with 25, 23, 21, 19 and 17 pins. Each pin can be set to be active or inactive. All five wheels turn one step after each letter.

  • A cage of bars, each with a lug that lines up with one of the pin wheels. When the lever turns the cage, each lug whose wheel has an active pin in position pushes the printing wheel one more step.

The number of steps the printing wheel turns is the key for that letter. Because the pin wheels turn after every letter, the pattern of active pins changes from letter to letter. The wheel sizes share no common factors, so the pattern of pins only repeats after

25⋅23⋅21⋅19⋅17=3,900,22525 \cdot 23 \cdot 21 \cdot 19 \cdot 17 = 3{,}900{,}225

letters. Compare that with a Vigenère keyword, which repeats every few letters.

The M-209

The M-209 is the U.S. version of the C-38. About 140,000 were built, and the U.S. Army used it widely during World War II for messages in the field. It added a sixth pin wheel and has 27 bars, so its pin pattern takes even longer to repeat.

Here is an example. The machine produces a key number for each letter, and the M-209 subtracts the plaintext from it:

C=K−P(mod26)C = K - P \pmod{26}
     plaintext:  h   u   s   h   h   u   s   h   h   u
plaintext (P):   7  20  18   7   7  20  18   7   7  20
key (K):        17  21   0   5  18   9   2  20  21   5
K - P mod 26:   10   1   8  24  11  15  10  13  14  11
    ciphertext:  K   B   I   Y   L   P   K   N   O   L
KBIYLPKNOL
hushhushhu

The repeated plaintext hush becomes KBIY, then LPKN, then OL...: the same plaintext letters give different ciphertext letters each time, just as in a Vigenère cipher with a very long key. Because K−(K−P)=PK - (K - P) = P, the same machine settings both encipher and decipher, which made the machine easy to use.

The M-209 was not unbreakable. German codebreakers could read some M-209 traffic during the war, but usually days after it was sent, which was too late for most battlefield messages.

Crypto AG

Hagelin’s company moved to Switzerland and became Crypto AG in 1952. It sold cipher machines to governments around the world. In 1970 the CIA and West Germany’s intelligence service (the BND) secretly bought the company. For decades, in an operation code-named “Thesaurus” and later “Rubikon”, Crypto AG sold machines with weakened encryption that the two agencies could read.

The Enigma Machine

Arthur Scherbius (1878 to 1929) was a German electrical engineer who patented the Enigma in 1918. It was one of several rotor machines invented around that time. The Enigma was first sold to businesses, for example for bank messages. Modified versions were adopted by the German Navy in 1926, the German Army in 1928 and the German Air Force in 1935.

The Enigma is electromechanical. When the operator presses a key:

After each key press, the rightmost rotor turns one step (and now and then the next rotor turns too, like an odometer). So every letter is enciphered with a different substitution alphabet: the Enigma is a polyalphabetic cipher whose alphabets are made by the rotors. The reflector means that enciphering and deciphering are the same operation, so a receiver with the same settings types the ciphertext to get the plaintext. It also means that no letter can ever be enciphered as itself, a weakness the codebreakers used.

How many keys?

Here is a count of the settings for the German Army’s Enigma of the early 1930s, which had 3 rotors and 6 plugboard cables:

  • put the 3 rotors in order: 3⋅2⋅1=63 \cdot 2 \cdot 1 = 6

  • ring settings on 2 of the rotors: 26⋅26=67626 \cdot 26 = 676

  • starting positions of the three rotors: 26⋅26⋅26=26326 \cdot 26 \cdot 26 = 26^3

  • 6 plugboard cables, each joining 2 different letters:

    26!14!⋅6!⋅26=100,391,791,500\frac{26!}{14! \cdot 6! \cdot 2^{6}} = 100{,}391{,}791{,}500

(Here 14!14! counts the orders of the 14 letters with no cable, 6!6! the orders of the 6 cables, and 26 the two ends of each cable, since none of those orders change the plugboard.)

plugboard settings: 100,391,791,500
total settings:     7,156,755,732,750,624,000

That is about 7.16×10187.16 \times 10^{18} settings. By 1939 the Army had 5 rotors to choose from and used 10 plugboard cables, which made the count far larger. Trying every setting by hand was impossible. Even so, the Enigma was broken: first by Polish mathematicians led by Marian Rejewski in the 1930s, and then during World War II at Bletchley Park in Britain, where Alan Turing and others built machines called bombes to search for the day’s settings. They used mistakes in how the machines were operated, predictable words in messages, and the fact that no letter is ever enciphered as itself.

Other Machines and the End of an Era

Other countries built their own machines, such as SIGABA (United States), Typex (Britain), NEMA (Switzerland), and the German Lorenz SZ40/42 teleprinter cipher, which the British called “Tunny”. As computers grew more powerful, mechanical machines became slow and impractical. Electronic systems replaced them in the 1960s and 1970s.

These machines produce keystreams that look random, but they come from a fixed mechanism and a key setting. That makes them almost a one-time pad, but not quite, and the difference is what made them crackable. Chapter 10 picks up this idea with stream ciphers built from binary digits.

Exercise for the Reader