The Enigma
UC Berkeley - Fall 2018

enigma machine

Overview

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.

The Code

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.

Example

enigma program configuration file example

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.

enigma program input file example

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.

enigma program output example

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!

Languages and Tools Used

java logo
git logo
back arrow

Back to Projects

back to top arrow

Back to Top