I implemented a program that simulates the German Enigma encryption and decryption machine from WWII in Java. The program includes functions that represent the functionality of the physical pieces of the machine like the rotors, reflectors, pawls, and the plugboard. The program can take in configurations and a message or cipher text and encrypt or decrypt the text using the same progressive substitution cipher technique as the actual Enigma machines.
I implemented different classes to represent the pieces of the machine like different kinds of rotors and reflectors, and also needed functionalities like permutations and character ranges. All of these classes were put together in a “machine” class that simulated the entire Enigma process by scanning input files, running the setup and encryption/decryption process, and building an output file.
In this example, my Enigma program is configured with the above file. The program takes in uppercase letters A-Z, and has eleven rotors and eight pawls. The next lines have the name of a rotor (I to VIII, Beta, Gamma, and reflectors B and C), a denotation for rotor type (non-moving, moving, or a reflector) and its notches, and the cyclical permutations in parentheses.
The input file shown above has a line of settings, and then the message to be encrypted. I made my message a homage to Alan Turing, an English mathematician who played a big part in cracking the Enigma machines during WWII, and actor Benedict Cumberbatch who played Turing in the movie The Imitation Game. The second message to be decrypted is the ciphertext of the plaintext message, to check for correctness.
The output of running the messages through the Enigma program is shown above, and the encryption and decryption of the messages with the given settings come out correct. The Enigma has been cracked!