Wikijunior:Raspberry Pi/Raspberry Pi Enigma Machine

Presentation
GCHQ and Raspberry Pi Foundation CC-BY-SA 4.0

Based on the Raspberry Pi OctoPi tutorial: https://projects.raspberrypi.org/en/projects/octapi-brute-force-enigma

What is the Enigma machine?
An Enigma machine is a device used for encrypting and decrypting messages. It was developed in the early 20th century and was used extensively by the Germans during World War II to encode their military communications.

The Enigma machine was famously broken by Alan Turing and his team at Bletchley Park, who developed techniques for cracking the Enigma code. This played a crucial role in the Allied victory in World War II, as it allowed them to intercept and decode important messages sent by the Germans.

How does the Engima machine work?
YouTube

The Enigma machine consists of:
 * a keyboard for typing in the message
 * a series of rotors that perform the encryption and decryption
 * a reflector that bounces the electrical current back through the rotors in the opposite direction

The rotors can be set in different positions, allowing for a large number of possible combinations and making it difficult for an attacker to decode the message.

Worksheet
Consulting your Enigma settings sheet, you find out that the settings for today are as follows:

What is the decrypted message?
Here is the secret message:
 * 1) Open Python 3, then open the file called
 * 2) Type in the chosen rotors between the green quote marks   next to.
 * 3) Now type in the letters for the rotor start position between the green quote marks   next to.
 * 4) Type in the message key   between the green quote marks   next to.
 * 5) Type in the plaintext which is the secret message.
 * 6) Run the program by pressing the F5 key (say yes to saving).

Can you decrypt this message?
Use the same Enigma settings but don’t forget to change the message key:

Encrypt a message

 * 1) Open Python 3, then open the file called
 * 2) Type in the chosen rotors and the rotor start position again from the settings sheet
 * 3) Type in the message key   between the green quote marks   next to.
 * 4) Run the program and check it works – the resulting cipher text should be   for the plain text.

Now it’s time to encrypt your own message!


 * Choose a different three letter  and type it in
 * Choose a different plaintext message and type it in. Make sure there are no spaces!
 * Run the program, then write down the encrypted key and the cipher text and give it to someone else to decrypt

Challenge
Decrypt this message:

Brute force attack
You need to know the Enigma settings to be able to decrypt the message!

Here are today's settings. Unfortunately, someone has spilt some ink on the rotor settings 😟

Crib text is where you know both the plain text and the cipher text. Crib text: WEATHER Cipher text: VZTLMPU Can you decrypt this message using a brute force attack if you know the crib text and part of the settings?

Brute force attack

 * 1) Open Python 3, then open the file called.
 * 2) Type in the crib text and the corresponding cipher text.
 * 3) Run the brute force attack to find the rotors and the message key.

Decrypt the message
Now open the  program you used before. Type in the  setting, and this time you will need to type in the ring​ and ​plug board​ settings from the settings sheet as well. Type in the  you found via the brute force attack. This time we already know the decrypted message key. Find this line of code: . 

Change it to say  where   is the three-letter key you found in the brute force attack.
 * What is the secret message?

Final challenge
18/05/18

Setup
This tutorial uses the py-enigma module by Brian Neal to provide the Enigma machine functionality.

You can install a copy of py-enigma on your Raspberry Pi (or your computer) by running this command from the Terminal:

Files
The original PDFs for this tutorial are available on Wikicommons: