CSC 427: Data Structures and Algorithm Analysis
Fall 2008

HW1: Enigma Simulator


Enigma Machine

Substitution ciphers that encode a message by substituting one character for another go back at least as far as Julius Caesar, who used a rotating character scheme to encode military orders. This simple type of encryption is vulnerable to statistical attacks, however, as anyone who has solved CRYPTOGRAM puzzles can attest. In World War II, the Nazi military employed an encryption scheme that addressed this weakness of simple substitution ciphers. This scheme, implemented by typewriter-sized devices known as Enigma machines, gave the Nazis a tactical advantage that greatly contributed to their early success in the war. Efforts to break the Enigma code led to the development of the first electronic computers at Bletchley Park, England: the Bombe (designed by Alan Turing) and its successor, Colossus (designed by Tommy Flowers). Using computers, the Allies were eventually able to break the Enigma code, giving them an intelligence edge that changed the balance of the war.

Enigma Rotors

The Enigma machine utilized interchangeable rotors with internal circuitry that mapped each letter of the alphabet to a different letter. When placed side-by-side on a spindle, three rotors would define an even more complex substitution pattern, with the wires inside each rotor connecting to its neighboring rotors. When the operator hit a key on the Enigma keyboard, an electrical current would flow through the wires in the rotors, forming a closed circuit and lighting up the letter specified by the rotor substitution pattern. The substitution pattern defined by the circuit was symmetric, meaning that if 'E' was mapped 'Q', then 'Q' would likewise be mapped to 'E'. Thus, the same rotor settings would work to encode and decode a message.

What made the Enigma code especially difficult to break was that the rotors moved before each letter was encoded, essentially changing the substitution pattern each time. In particular, the rightmost rotor rotated one position on every encoding, and the other rotors rotated conditionally, based on the position of pegs and notches on the rotors. Thus, the letter 'E' might get mapped to a 'Q' the first time it was encountered, but to a completely different letter each successive time.

The original Enigma machines used at the beginning of World War II had three rotors, which could be placed on the spindle in any order (giving 3! = 6 possible combinations). In addition, each rotor could rotated by the operator so that a desired letter showed in a window (giving 26 possible orientations for each rotor). Thus, the total number of possible initial settings for an Enigma machine was 6 * 26 * 26 * 26 = 105,456.

For a complete discussion of how an Enigma machine worked, see the Wikipedia article. Furthermore, to actually experience the workings of an Enigma machine, download the Do-It-Yourself Enigma Machine and follow the directions to construct a working model out of paper. Using this paper machine, you should be able to encode and decode messages using the same algorithm as an Enigma machine. To test your understanding, set the initial configuration to I-W, II-Q, and III-T. That is, ROTOR I should be placed leftmost with the letter W on its left side aligning with the rotor setting line; ROTOR II should be in the middle with Q at the rotor setting line, and ROTOR III should be rightmost with T at the rotor setting line. Then decode the message "UKJAFO".

For this assignment, you are to write a program that simulates the workings of an Enigma machine, as described in the Wikipedia article and made concrete by the paper model. In designing your solution, you should strive to follow good object-oriented design principles. That is, define highly cohesive classes that correspond to real-world objects, and make sure those classes are loosely coupled so that the implementation details of one are independent of the others. You must demonstrate good programming style when completing this assignment, including the appropriate use of Javadoc-style comments for all classes and methods. The interface for your Enigma program is entirely up to you. It need not be fancy, but it must at least allow the user to select the order and settings of the rotors and subsequently encode/decode messages.