Enigma Machine

Suppose you want to send a secret message to a friend named Alice. You could call Alice and tell her the message, but you're concerned that someone may be listening to the call, and you don't want anyone else to know what you have to tell her.

What you want to do is encrypt the message. You make an agreement with Alice on some rules for encrypting the message — rules that only the two of you know. When you send the message you apply those rules, and Alice receives the encrypted message. Then she uses the rules to decrypt the message. Even if someone is listening, they won't know the original message unless they can decrypt it.

Caeser Cipher

One of the simplest methods of encryption is known as a Caeser cipher. Used by Julius Caeser, this cipher shifts letters in a message by a constant number of letters. For example, with a "right shift" of 1, A becomes B and B becomes C.

To send Alice the message "HELLO" with a right shift of 2, you would send "JGNNQ".

H E L L O
I F M M P
J G N N Q

To decrypt the message, Alice shifts all of the letters down by 2.

J G N N Q
I F M M P
H E L L O

If someone is trying to listen to the message you send to Alice, and either heard you tell Alice the message, or were listening when Alice received the message, they would get the message "JGNNQ". Unless they figure out how to decrypt it, the message you sent to Alice is secure.

Use a Caeser cipher:

Encrypted message:


Now that we've gone into the concept of encryption, we will explore Enigma machines and how they encrypt and decrypt messages.

Let's start with an exploration of how the machine is operated, before getting into the encryption process. To encrypt a message, the user of the machine types on one of 26 keys. The Enigma machine used a QWERTZ keyboard. You can switch to QWERTY.

Start typing or clicking on keys on the machine — whatever you type will be highlighted on the "lampboard" on top.

The Enigma machine supports the 26 characters Latin letters in the German alphabet — the same 26 letters as the English alphabet. There are no spaces, commas, periods, or other punctuation.

To encrypt a message, a user presses a key, and then writes down which letter on the lampboard lights up. Because this example doesn't have any encryption, the letter on the lampboard that lights up is the same as the letter that is typed.

Let's now investigate how the Enigma machine encrypts a letter. To do this we will "build" the machine from scratch, adding a new part with each step.

There are two parts to encrypting a message: the rotors and the plugboard. We will go through each of the steps of encrypting a letter one step at a time.

Rotors

Each Enigma machine comes with five rotors, which have a predefined transformation of each letter. Here is a sample rotor:

This table demonstrates how the wiring is mapped for one of the rotors.

# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Original A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Substitution E K M F L G D Q V Z N T O W Y H X U S P A I B R C J

Rotors have internal wiring that determine how each letter is transformed. In the example above, the wire for the first letter's pin, A, goes to the output E. This means that the letter A (the first letter in the alphabet) is transformed to a E (the fifth letter in the alphabet). The letter B is transformed to a K. This is known as a substitution cipher — a Caeser cipher is also a substitution cipher.

Rotors are placed inside the machine. In the example below, one rotor is placed and is highlighted in green.

When a user of an Enigma machine types the letter A, the signal passes through the rotor, and the letter E is output. Each letter is mapped to another letter. Try using the Enigma machine with this rotor added. There is now a "1" highlighted in orange towards the top of the machine, to note the placement of the rotor.

Now the machine has some simple encryption — each letter outputs a different letter, rather than the original letter like the previous example. This is similar to the Caeser cipher, except rather than incrementing each letter by a constant amount, there is no defined formula for changing one letter to another.

In the current example, each time a letter is typed, it is mapped to the same letter, like a Caeser cipher. For example, typing "hello" on the machine above will output "qltty", which is insecure -- it lets potential eavesdroppers know that a letter was repeated twice, which can be used to help decrypt the message.

To further increase the entropy, or randomness, the first rotor moves every time a letter is typed. Using the rotor above, this means that if "A" is typed it outputs "E", but if "EK" is typed it outputs "EK". K is the substituted letter in the second position.

Try out a machine with a rotor that rotates each time a letter is typed, and note that the "1" towards the top of the machine increments each time a letter is typed, and goes back to 1 after 26.

The Enigma machine uses three of the five rotors to encrypt and decrypt messages.

With three rotors in place, letters now pass through a more complicated process. Consider three rotors with the following mappings; the first rotor is the same as the one above:

Rotor #1
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Original A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Substitution E K M F L G D Q V Z N T O W Y H X U S P A I B R C J
Rotor #2
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Original A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Substitution A J D K S I R U X B L H W T M C Q G Z N P Y F V O E
Rotor #3
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Original A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Substitution B D F H J L C P R T X V Z N Y E I W G A K M U S Q O

After a letter goes through the first rotor, it then goes through the second and third rotor. With the configuration above, and without rotating the rotors, the message "HELLO" becomes "IPNNY".

  1. User types an H -> Rotor #1 converts H to Q -> Rotor #2 converts Q to Q -> Rotor #3 converts Q to I -> I is highlighted on the lampboard
  2. User types an E -> Rotor #1 converts E to L -> Rotor #2 converts L to H -> Rotor #3 converts H to P -> P is highlighted on the lampboard
  3. User types an L -> Rotor #1 converts L to T -> Rotor #2 converts T to N -> Rotor #3 converts N to N -> N is highlighted on the lampboard
  4. User types an L -> Rotor #1 converts L to T -> Rotor #2 converts T to N -> Rotor #3 converts N to N -> N is highlighted on the lampboard
  5. User types an O -> Rotor #1 converts O to Y -> Rotor #2 converts Y to O -> Rotor #3 converts O to Y -> Y is highlighted on the lampboard

The message "IPNNY" is output.

Like the first rotor, the second and third rotors also rotate. While the first rotor rotates every time a letter is typed, the second rotates every 26th letter, and the third rotates every 676th letter (26 * 26). Here is the example above, considering the rotations. Only the first rotor rotates in this example because it has fewer than 26 letters.

  1. User types an H -> Rotor #1 converts H to Q -> Rotor #2 converts Q to Q -> Rotor #3 converts Q to I -> I is highlighted on the lampboard
  2. User types an E -> Rotor #1 converts E to G -> Rotor #2 converts G to R -> Rotor #3 converts R to W -> W is highlighted on the lampboard
  3. User types an L -> Rotor #1 converts L to W -> Rotor #2 converts W to F -> Rotor #3 converts F to L -> L is highlighted on the lampboard
  4. User types an L -> Rotor #1 converts L to Y -> Rotor #2 converts Y to O -> Rotor #3 converts O to Y -> Y is highlighted on the lampboard
  5. User types an O -> Rotor #1 converts O to S -> Rotor #2 converts S to Z -> Rotor #3 converts Z to O -> O is highlighted on the lampboard

The message "IWLYO" is output.

Here is an updated Enigma machine that factors in the three rotors and their rotations.

History

We've gone through a lot of the mechanics behind the Enigma machine. Let's take a break from the functionality and consider how they were used in practice.

Arthur Scheribus applied for a patent for a rotor ciphering machine in 1918. The first Enigma models were mainly used by businesses for sharing messages that had confidential information. There are dozens of model of Enigma machines. The model explored in this post is the Enigma I, a common model used by the German military in World War II.

Every month, the German military distributed a sheet with the daily configuration of a machine. At the start of each day, the operator of a machine set their machine to these settings. Here are the things that can be configured on a model machine:

This is what a sample monthly sheet was like:

With a sheet and an Enigma machine, a user can encrypt and decrypt messages. Early in the war, the Allied powers obtained an Enigma machine and learned how they work. Even knowing how they work, without knowing the configuration settings of the machine, the Allied powers still had significant trouble decrypting messages because of the complexity of the encryption. On occasion the Allied powers successfully obtained one of these sheets, and could decrypt messages sent by the German military for that month.

Reflector

The Enigma machine also includes a reflector. This goes after the third rotor, and sends the signal back through the rotors.

The reflector is similar to the rotors because it substitutes one letter for another, but it has a unique property: letters are mapped in pairs. For example, A maps to E, and E maps to A. B maps to J, and J maps to B.

Using the sample rotor configuration above, the letter "A" is encrypted like:

  1. User types an H
  2. Rotor #1 converts A to E
  3. Rotor #2 converts E to S
  4. Rotor #3 converts S to G
  5. Reflector converts G to Y sends the signal back to Rotor #3
  6. Rotor #3 converts Y to Q
  7. Rotor #2 converts Q to Q
  8. Rotor #1 converts Q to X
  9. X is highlighted on the lampboard

We've now covered a fully functional Enigma machine, which you can explore below.

We're still missing one optional component used by the German military: the plugboard.

Plugboard

The plugboard is fairly simple, but adds a significant amount of complexity to the encryption process. Each Enigma machine comes with ten wires, known as . These wires can be used to do another transformation of letters, like the rotors.

The front of an Enigma machine has every letter with a hole next to each letter. The wire has two ends, and each end goes into one of the letter holes. For example, one end of a wire might go into an A while another goes into B. This would mean that all As are transformed into Bs, and all Bs are transformed into As.

Each machine comes with ten wires, but not all ten need be used.

Once a letter has been through the three rotors, it goes to the plugboard. Here is the previous example encrypting an "H", adding in the plugboard:

  1. User types an H
  2. Rotor #1 converts H to H
  3. Rotor #2 converts H to H
  4. Rotor #3 converts H to H
  5. Reflector sends the signal back to Rotor #3
  6. Rotor #3 converts H to H
  7. Rotor #2 converts H to H
  8. Rotor #1 converts H to H
  9. The plugboard converts H to H
  10. H is highlighted on the lampboard

That is all of the steps that goes into encrypting messages on an Enigma machine.

Here is a fully functional Enigma machine. You can configure the settings to whatever you like. The machine's default configuration is from the German military's configuration on .

Decrypting

To decrypt a message on an Enigma machine, an operator of a machine sets the machine to the daily configuration, and inputs the encrypted message. The decrypted message is then highlighted on the lampboard.

Complexity

A Caeser cipher has a complexity of 26, meaning there are 26 possible ways of encrypting a message.

An Enigma machine with one rotor that does not rotate also has a complexity of 26 because like a Caeser cipher, each letter is mapped to one other letter.

But an Enigma machine's rotor does rotate, and this means that each letter can be mapped to 26 different letters, making the complexity of an Enigma machine with one rotating rotor 26*26 = 676.

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text

this is a lot of text