Writing an Enigma Simulator Enigma logo (click for homepage)

Contents
Introduction
Ever since I first heard about Enigma, I was fascinated by it. But it was not until I attended a lecture about WWII technology, that I really wanted to know more about it. After reading Robert Harris' novel Enigma, I visited Bletchley Park in the summer of 2001. The trip was worth while and I can recommend a visit to Bletchley Park to anyone interrested in the matter. The whole story, from the listening stations at the coast line, to the actual code breaking, is demonstrated and visitors can try to decode a 'real' message on one of the Enigmas on display.

The look and feel of the Enigma is rather unique, and the thought that this piece of wood and metal was actually used to encode and decode messages during WWII, makes it even more special. Wouldn't it be nice to have such a unique piece of history for yourself? The only problem here is that the machines are rare these days and that their price is running between GBP 20,000 and GBP 100,000. Nevertheless I wanted to 'have' one, in order to be able to study the coding process used by the Germans during the war and the Bletchley Park efforts to break it.

When I came home after the holidays, I searched the Internet for useful Enigma simulations. I found a couple of Java applets, but some of these didn't produce the expected results. Although they explained the working principle of the Enigma, they didn't simulate the actual device. I also found the Enigma Simulations for Windows, by the CSG (the Crypto Simulation Group). These are written by experts on the Enigma subject and produce correct results. The only problem here is that they are running on Windows and not on RISC OS. I then decided to create my own version of the Enigma Simulator expecially to run on RISC OS.

Paul Reuvers enigma@xat.nl 

Writing the simulator
Before writing the actual simulator, I had to study the subject and get to grips with the mechanical functionality of the Enigma. I read a couple of books and found some interesting documents on the Internet, most of them written by David Hamer and other members of the CSG. This documentation was very useful and I learned that the Enigma is not a single device. In fact, many variants, both mechanical and electrical exist, and most of these are not compatible with each other.

In the section below I've tried to explain the working principle of the Enigma and after that, I will try to explain the differences between the various models. In order to produce reliable results, I had to implement the characteristics of each Enigma variant and this has resulted in a set of 'profiles' used to describe each model. To make the simulations more realistic, I've added a texture, or skin, and a realistic sound recorded from a real Enigma by Jim Oram in the USA who is currently building an Enigma-replica. The 'skin' of each model has been carefully deduced from the many pictures in books and on the Internet. If you come across a detailed image that may be of use to me, please feel free to send me a copy by email.

For the purpose of studying the working principle, a visual scrambler has been added that will show the flow of the electric current in real time, whenever a button is pressed. Furthermore the full wiring and behaviour of each of the coding wheels of the Enigma can be studied in separate windows.

Working principle
When studying the working principle of the Enigma, we have to consider that there are in fact many different variants of this machine. Some of the differences make it impossible to decrypt a message that was encoded on another model. That does however not affect the working principle as explained here. For this we study the circuit diagram of an Enigma M3.


Letters are 'scrambled' by a set of rotatable wheels each with 26 contacts on either side. Each contact on one side is connected (wired) to a contact on the other side in some random fashion. Some models, like the M3 have 3 such rotating wheels, but the M4 model, used later in the war during the U-boat war, has 4 wheels. Each time a key is pressed, the right most wheel is rotated by one step, resulting in a different mapping of the internal wires. A wheel has one or more notches that may cause the next wheel to be moved by one position too. This will result in a different encoding for each letter entered on the keyboard!

The keyboard consists of 26 keys, marked A-Z. Whenever a key, say Q, is pressed the wheels will be moved into a new position and a contact is closed. As a result a current will flow. The wires from the 26 keys are connected to a static wheel called the Stator or Entrittswalze (ETW). The order in which the keys are connected to the 26 contacts on the ETW varies between the different Enigma models.

Leaving the ETW, the current enters the right most wheel (1) at the right hand side. The internal wiring of that wheel 'translates' this to one of the contacts of its left hand side, where it enters the next wheel, etc. Left of the rotating wheels is the Reflector, or Umkehrwalze (UKW). This wheel sends the current back into the rotating wheels, but this time the current flows from left to right, until it reaches the ETW again. From the ETW the current goes to the lamp board where the corresponding letter (W in the example) will be lit. It is inherent to this design, that a letter can never be enocoded into itself.

Before starting the cyphering process, the Enigma needs to be setup in a known way by both sides. This means the wheel order (Walzenlage) needs to be known as well as the starting position of each wheel (Grundstellung). In order to further complicate things, each wheel has a settable index ring that moves the contacts independant of the wheel's alphabet. This is called the ring setting (Ringstellung).

To make life even more complex, some models are equipped with a plug panel (Steckerbrett) that allows letters to be swapped. Between none and 13 of such mappings may be added. If a key is not mapped (i.e. no stecker is used for that key), the letter is known to be Self-Steckered. See below for more information.

Wheel rotation in more detail


When writing the Enigma Simulator, I had to find out exactly how the wheels are moved with each key press. First of all, the wheels are moved into a new position, before the key is encoded and the lamp is turned on.

Each wheel has 26 positions that we will call A-Z. The index on the wheels is engraved (either as A-Z or 1-26) along the side of the wheel. The wheels are rotated clockwise, when viewed from the ETW. If A was visible in the window, the letter B will be visible next time the wheel is moved. Each wheel has a ring that can be used to rotate the wiring independantly from the index. This can be regarded as creating an offset in the opposite direction. The notches are fixed to the index. Therefore the turnover of the next wheel, will always happen at the same letter in the window.

Furthermore most models are equipped with stepping levers and notches and will therefore exhibit a double stepping feature (see below). The Enigma G series however, uses a gear and does not suffer from the double stepping behaviour.
Wheel
Exploded view of a wheel
(Photo by Jerry Proc)
The Steckerbrett


The naval variants of the Enigma (M3 and M4) were equipped with a Steckerbrett (plug board or patch panel) that would allow any pair of letters to be swapped. If a patch cable was used beteen G and P, those two letters would be swapped. As we have 26 characters, a theoretical maximum of 13 cables could be used. Most machines however, were supplied with less (e.g. 10 or 11) cables.

Note that any amount of cables can be used, from none to 13, giving a much increased number of possible permutations. As the Steckerbrett is connected between the keyboard and the ETW, the encoded letter will go through stecker mappings twice. This would prevent a letter of being encoded into itself.

The picture shows single patch cable. To prevent a plug from being inserted in the wrong way, a thick and a thin pin were used. Two wires were used to cross-connect the pins of both plugs.
Patch cable
An original Enigma patch cable
(Photo by Jim Oram)
Differences in Enigma models
It has been stated before that there are many different versions of the Enigma. The various models may differ in:
  • Steckerbrett
    Some models have a plug panel and some don't. The theoretical maximum number of patch cables is 13 (as we have 26 letters), but the amount of cables supplied with the unit varies.
  • ETW mapping
    The ETW can be mapped in a linear fashion: ABCDEFGH... etc, but also in the order of the keys on the keyboard: QWERTZUIO... On the Japanese machine, the Tirpitz, the contacts of the ETW are organised in a random fashion: KZROUQHY...
  • Amount of wheels
    Some models have 3 rotatable wheels, but the M4 has 4 wheels. Also some models have more wheels (e.g. 8) to choose from. The wheels may be placed in the machine in any particular order. On a 4 wheel machine (M4), the extra wheel is not moved automatically, but can be set manually to an initial position. Furthermore the extra wheel cannot be exchanged with the other three wheels as it is a 'thin' one. The 4th wheel was supplied as a pair with an UKW. For UKWs B and C, the extra wheels Beta and Gamma where supplied, hence the name Griechenwalze (Greek wheel). They may be used however in any combination.
  • UKW mapping and setting
    Some models have more than one UKW available. On most models the UKW is fixed, but on some the UKW can be given a start position. Additionally, the G models have a movable UKW, which means that the wheel can be moved by the notches of the wheel next to it.
  • Amount of notches on each wheel
    In the basic situation, each wheel has one notch which, after a full revolution, causes the next wheel to be stepped by one position. Some versions have two or even more notches on each wheel, causing more frequent changeovers of the next wheel.
  • Single or double stepping
    As a result of the mechanical principle of the stepping mechanism, the middle rotor 'suffers' from a double stepping anomaly as described in a paper by David Hamer (see below). The G models, who use a gear box instead, do not suffer from this anomaly.
Recommended reading
Thanks are due to...
  • David Hamer
    for providing advice, images and messages,
  • Frode Weierud
    for providing advice, kind words and additional wiring information,
  • Jim Oram
    for provinding the sound samples used in the simulator,
  • Computer Simulation Group
    for providing high quality Enigma Simulators for Windows.

© Paul Reuvers enigma@xat.nl  Last changed: Sun,16 Sep 2001.17:05:57
Logo (click for homepage)