The Enigma Enciphering Machine

A few years ago I saw a program on the history channel which sparked my interest. Entitled 'Breaking the Codes', the series outlined cryptography focussing on technologies developed during World War II. One of the best examples of this technology was the Enigma machine developed by the Germans.

The Enigma was an incredible machine and used an encryption method the Germans felt was unbreakable but procedural errors in using the machine allowed the Poles and later the British to crack the "unbreakable" codes.

The Enigma Enciphering Machine

The Technology of the Enigma

Simple mono-alphabetic substitution ciphers have been around for a long time but they suffer the severe disadvantage that the same plain text message is always encoded as the same enciphered characters. Breaking such a code is quite trivial. The Enigma cipher machine used a series of rotors which continually changed the wiring for each character to be encoded. Encoding a string of 'A''s will not produce the same enciphered output character but rather a string of garbled text.

The actual machine was developed in 1918 by Arthur Scherbius as a machine to allow businesses to communicate confidential documents. It was later (much later) adopted by the German Navy. The machine had a keyboard which allowed the user to enter a character. The electrical signal from that key was swapped for another letter by a rotor (for example, the letter 'A' might emerge from the first rotor as 'E'). The signal emerging from the first rotor then went through two other rotors to be further scrambled.

Now for the real trick: the rotor advanced one position for each letter enciphered. Each rotor had 26 positions (one for each letter of the alphabet) and once a rotor had advanced 26 positions it would start over - after advancing the next rotor to the left much like a car odometer does. If only one rotor were used, transposition would be repeated after 26 letters. With two rotors it occurred after 26 x 26 = 676 letters, with three 26 x 26 x 26 = 17,576. This made the enciphered code very difficult to decode.

Refinements ...

The Enigma machine had a fixed umkehrwalze (or reflecting rotor) on it's left side after the third rotor which "reflected" the electrical pulses back through the string of 3 rotors in the opposite path. This resulted in reciprocity between encipherment and decipherment; if "a" was enciphered as "X" then "x" would be enciphered as "A" so that this machine could either encipher or decipher at any given rotor setting. The disadvantage was that if somehow one letter of a message was decoded, a second one would also be known. As well, no letter could ever represent itself.

Another complication added was the Steckerboard, a a plug board with 26 jacks and a number of patch cords (usually 6) which could cross-connect any two letters between the keyboard and the rotors. This raised the number of possible encipherments to a staggering 10 quadrillion. You can understand why the Germans were convinced that their codes were quite unbreakable!

Enigma Encoding Example

In the above example the letter 'Q' is to be enciphered. 'Q' is changed to 'Y' via rotor #1, 'Y' to 'S' via rotor #2, and 'S' to 'N' via rotor #3. Now the signal is reflected back into the rotors as 'K' then 'C', then 'X', and finally the output character 'U'. After this single character is encoded rotor #1 is stepped one position which changes the mapping of the characters entirely so pressing 'Q' twice does not produce two consecutive 'U's as output.

The Enigma codes were broken first by the Poles who, as you might imagine, looked at their German neighbours as potential adversaries. The story of how the codes were broken is also a fascinating story, one best described in the first link below.

A Modern Version ...

ENIGMA-P: MCU-based Encipering Peripheral

Introduction

The ENIGMA-P chip is a single-chip RISC microcontroller which allows both encipherment and decipherment of text based on the original ENIGMA algorithm as developed by the Germans during WWII. The chip emulates the three-rotor ENIGMA machine using firmware. The chip may be used stand-alone or may be interfaced to a PC through an appropriate interface.

Electrical Interface

ENIGMA-P is based on a PIC 16C84 or 16F84 18-pin microcontroller from Microchip, Inc. This CMOS microcontroller features very low power consumption (a few mA at most) allowing it to be powered from a PC port without the need for a separate power source.

The interface consists of twelve TTL-compatible logic lines as follows:

Timing diagram

The diagram below outlines the timing of a typical cycle in which a text character is enciphered.

Symbol Parameter Function Min. Max
tDS Data Setup before strobe 0
tDH Data Hold after strobe transition 20
tSTR Strobe pulse width 12
tENC Encode time for one character 100 1600
tRL Strobe high to ready low 4 16
tODS Output Data Setup before ready 25
tSLR Strobe low to ready high 4 16

NOTES:

Typical Application

The ENIGMA-P chip may be used as a standalone encryption unit or as a peripheral for a computer system by interfacing it appropriately. In the case of a standalone unit, all that is required for operation is six switches and six LEDs which may be wired to the chip as follows:

This MCU, like all other, requires a clock source. To reduce complexity and cost an RC oscillator is used as shown and must be included in the circuit.

Five switches are used to enter the character to be enciphered, the sixth switch, a pushbutton, being used as a strobe. Note that inputs to this chip are CMOS so that they will NOT float high if left unconnected - pull-up resistors are required (In the range of 1K0 to 4K7). To encipher a character set the strobe input LOW and apply power. This initializes the rotor positions to 'AAA' or '00 00 00'. Enter the code for the character to be enciphered on the five data switches (00000 for "A", 00001 for "B", etc.). Next the strobe line is toggled high then low. The result appears on the data LEDs (The microcontroller also has CMOS outputs which can both sink and source current so LEDs may be wired active-high).

To verify the operation of the chip set the data switches all to LOW ("A"). The first enciphered output will appear as 0x0B (01011). The next output given the same input character 00000 will appear as 14 (10100). This verifies basic operation of the chip.

Firmware

Code for the ENIGMA-P was written in Microchip MPASM assembler format. Several tables are used to map characters as the rotors would and pointers are used to calculate the actual position of the rotor as it 'rotates' each time a character is enciphered.

To use the ENIGMA-P encipher system a PIC 16C84 or 16F84 microcontroller must be programmed with the firmware. Any programmer, commercial or homebuilt, may be used to do this as long as it supports Intel HEX format files. Set the configuration fuses on the chip for RC oscillator, Watchdog timer OFF, PowerUp timer ON when programming.

ENIGMA-P HEX FILE ready to program directly into the flash memory on the microcontroller

ENIGMA-P SOURCE (ASM) FILE the original source file allowing modifications. Use MPASM (Designed originally for ver 2.1 ... will need modification to run on newer versions. The software is available from Microchip from their web site for free) to assemble into a HEX file
ENIGMA-P SOURCE FILE updated for use with MPLAB 7.5x

The pattern for the rotors and the reflecting rotor was generated using a BASIC program which uses the 'random-seive' method to generate unique mappings.