The Enigma was a cipher used in World War II by Germany to encrypt military communications. The cipher was originally deemed unbreakable, but was broken by British cryptologists using some pretty clever thinking.

Let's go through the Enigma step-by-step, building up the cipher and see how it works, what its weaknesses are, and why it might be useful in your campaign.

All code is available on Github.

Substitution Cipher

A substitution cipher is one of the easiest ciphers there are. You simply shuffle letters around. The cipher can easily be cracked by checking letter frequencies.

Cipher Rotation

Suppose we fix the substitution cipher and embed it in a disk. Now, every time we go to encode a letter, we first rotate the disk by one letter.

We are effectively cycling between four different substitution ciphers, making decoding the cipher more difficult.

Multirotor

We can do even better by stacking several disks together. We won't rotate them in-sync, as that would effectively make it a one-rotor system. Instead, we always rotate the first rotor and only rotate the upper rotors when the one below has undergone a full cycle.

Again, we are effectively cycling between substitution ciphers, but the number of substitution ciphers is much larger. (4 above, 4*4 here).

Reflector

The next thing we will do is add a reflector to the back of the disk stack. It joins pairs of letters so that everything loops back through the disks. This has several effects:

You pass through the rotors twice

At every step letters are paired, so for every A -> B, you also have B -> A

No letter can map to itself

The second point has an excellent side effect that made using the Enigma quite nice in practice. Letters are paired, so if you encode a message, you can decode it by running the ciphertext through the machine as if it were the input text. The decoding setting is identical to the encoding setting! This reduces the amount of info you need to effectively use the system on the battlefield.

The third point is a source of great weakness, and was exploited by cryptographers to break the Nazi code. It allows for dictionary attacks.

Consider the example above. We intercept the ciphertext 'CTCSCCASSSACCC' over the radio. We want to break it. Suppose we think the sender included the word 'CAT' in their message. Cats are, after all, the first word that came to mind with the limited alphabet I chose.

We can place CAT at the beginning of the ciphertext and compare it: 'CTC'. We know immediately that the first three letters are not CAT, because C -> C is not possible.

So we slide CAT down one, and compare it to 'TCS'. C->T is possible. A -> C is possible. T -> S is possible. Hmm, that word could be CAT! Let's check it....

Searching for words like those found in daily weather reports was how the real Nazi code was broken, and it was made possible by the reflector.

Plugboard

The final thing we add is the plugboard. This was an extra layer on top that allowed the sender to switch around pairs of letters.

If you look at the number of possible machine states that you need to check for an Enigma machine, it turns out that most of them come from the plugboard.

Full-Size Enigma

The real Enigma had 26 letters, three rotors that could be chosen from a set of eight, and a plugboard that allowed for up to 10 letter pairs. The provided code was tested against an Enigma emulator and can be used to encrypt or decrypt real Enigma messages. Double-stepping is enabled for Enigma machines.

Use in Your Game

Now that we know how the Enigma is constructed, we can consider using it in game.

The basic components of Enigmas make good game tools and props.

You Find a Rotor

Perhaps the players find an enigma rotor, and must deduce what it is and how it was used. Decrypting a single-rotor rotation cipher when you have the physical rotor is a lot easier - you only have to try the 26 different possible starting positions.

You Find an Enigma

Perhaps the players have access to an entire Enigma machine! There are several emulators online that you could let the players play with.

Deciphering Enigma ciphertext yourself is incredibly difficult. The Nazis thought it impossible. It took immense resources and dedicated hardware to crack it back in the day. But we have computers now, and if your players are leet coders and code crackers you can let them have a stab at it.

Instead, I recommend giving the players encoded text, but then having to go about finding the code book / enigma settings to decode it. A plethora of options present themselves. Do they raid the officers quarters? Do you trust the street urchin who is willing to sell you a grubby piece of paper he found in the streets that contains funny numbers?

If you have an Enigma you can also use it. Do your players coordinate with allies, or each other, using their own code book? How do their enemies attempt to crack it? What are the players willing to do to prevent it from getting in the wrong hands?

Water-Soluble Codebooks

Code books play a huge role in cryptography. Everyone on your side has to know what the daily codes are so that they can send and receive messages. The Nazi codebooks were written with special ink such that they would dissolve when their U-boat sank.

In one famous case a Uboat was destroyed, and the Nazis evacuated, assuming that the water would destroy the code book. Three Royal Navy sailors boarded the sinking Uboat and recovered the codebook before it was harmed. This was crucial to helping the allied code breakers, especially since the axis did not know that the codebook was obtained.

A similar setup could be created for your campaign. Are your players willing to risk diving into the sinking Uboat?

Code

All code used for creating the visuals is available online. It is written in Julia, which is a free, open-source language.

You can use JuliaBox to get started.

Code is provided as-is, but feel free to submit issues and/or pull requests.