[Sam Greydanus] created a neural network that can encode and decode messages just as Enigma did. For those who don’t know, the Enigma machine was most famously used by the Germans during World War II to encrypt and decrypt messages. Give the neural network some encrypted text, called the ciphertext, along with the three-letter key that was used to encrypt the text, and the network predicts what the original text, or plaintext, was with around 96-97% accuracy.
The type of neural network he used was a Long Short Term Memory (LSTM ) network, a type of Recurrent Neural Network (RNN) that we talked about in our article covering many of the different types of neural networks developed over the years. RNNs are Turing-complete, meaning they can approximate any function. [Sam] noticed the irony in this, namely that Alan Turing both came up with the concept of Turing-completeness as well as played a big part in breaking the Enigma used in World War II.
How did [Sam] do it?
One key to RNNs and LSTMs for this application is that they are good at learning from data that are in the form of sequences, in this case sequences of alphabetic characters. When being trained on whole documents of text, they learn about words, punctuation and sentence structure. In the case of the Enigma, [Sam] trained his LSTM on randomly generated plaintext, randomly generated keys, and the resulting ciphertext generated using a crypto-enigma Python API. From that training, the LSTM network then learned an approximation of the Enigma’s switchboard, wheels and cables. Note that it was trained on data encrypted using only a single cable configuration and wiring built into the wheels, though it can handle different keys, meaning that it can handle wheels turned to different positions. You can find the full code for the neural network on [Sam]’s GitHub page. As you can see from this article’s banner, with 96-97% accuracy it did pretty well when making predictions i.e. decoding.
At the end of World War II, most Enigma machines were destroyed but our [Brian Benchoff] was lucky enough to see some damaged and restored ones while attending a Vintage Computer Festival East. But of course, who can resist making one, an example being this one with 3D printed parts. And there are many more here for you to see.