Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,3 +1178,9 @@ Rohanrao02:
github: Rohanrao02
author_image: 'blog-author.jpg'
email: "rohanrao.jh@gmail.com"
the-pinbo:
name: Inbasekaran Perumal
github: the-pinbo
author_image: 'Inbasekaran.png'
email: "inba2002.p@gmail.com"

181 changes: 181 additions & 0 deletions _posts/2022-04-10-enigma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
layout: post
title: "Turing's Enigma Problem"
author_github: the-pinbo
date: 2022-04-10 23:32:44
image: "/assets/img/"
description: "All about the Enigma cipher machine and its working."
tags:
- IEEE NITK
- Blog
categories:
- CompSoc
- Cryptanalysis
- Computer science
github_username: "the-pinbo"
---

# Enigma Machine

An **Enigma machine** is a famous encryption machine used by the Germans during WWII to transmit coded messages. An Enigma machine allows for billions and billions of ways to encode a message, making it incredibly difficult for other nations to crack German codes during the war .
Alan Turing and other researchers exploited a few weaknesses in the implementation of the Enigma code and gained access to German codebooks, and this allowed them to design a machine called a Bombe machine, which helped to crack the most challenging versions of Enigma.

![Military Enigma machine](/blog/assets/img/enigma/enigmaMachine.jpg)

## Contents

- Encryption
- How an Enigma Machine Works
- Enigma Encryption
- Cracking the Enigma Code
- See Also
- References

## Encryption

Enigma machines use a form of substitution encryption.

Substitution encryption is a straightforward way of encoding messages, but these codes are fairly easy to break. A simple example of a substitution encryption scheme is a Caesar cipher. A Caesar cipher shifts each letter of the alphabet some number of places. A Caesar cipher with a shift of 11 would encode an A as a B, an M as an N, and a Z as an A, and so on.
Below is an image of a Caesar cipher with a shift of 33.

![Caesar Cipher](/blog/assets/img/enigma/caesarCipher.png)

### Example

**_Using a Caesar cipher with a shift of 5, encode the message “math is fun”._**

![Caesar Cipher Example](/blog/assets/img/enigma/caesarCipherExample.png)

“Math is fun” can be encrypted by this scheme as “rfym nx kzs”.

### Implementation of a Caesar Cipher in Python

```python:

def CaesarCipher(message, shift):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
#make sure the message we work with is lowercased to match symbols in alphabet
message = message.lower()

result = ""
#run on each letter in the message
for letter in message:
if letter in alphabet:
#find the index of the letter in the alphabet
index = alphabet.find(letter)
#determine the shift
index = (index + shift)%(len(alphabet))

#deals with wrap around if index is greater than 26 or less than 0
if index < 0:
index = index + len(alphabet)

#adds letter to result
result = result + alphabet[index]

#if the symbol isn't a letter (like punctuation), just print that
else:
result = result + letter
#prints what the text would read if it were decrypted using each possible shift
#go through the list and figure out which shift gives you a sensible message
return result


print CaesarCipher("hello",1)
print CaesarCipher("ifmmp",25)
print CaesarCipher("abc",2)
print CaesarCipher("zzz",4)
```

But Enigma machines are much more powerful than a simple Caesar cipher.

Imagine that each time a letter was mapped to another, the entire encoding scheme changed. After each button press, the rotors move and repressing that same button routes current along a different path to a different revealed letter.

So for the first press of a key, one encoding (like the table in the example above) is generated, and when the second key is pressed, another encoding is generated, and so on. This greatly increases the number of possible encoding configurations. Each time a key is pressed on an Enigma machine, the rotors turn, and the code changes. This means that the message “AA” could be encoded as something like “TU” even though the same key was pressed twice.

## How an Enigma Machine Works

An Enigma machine is made up of several parts including a keyboard, a lamp board, rotors, and internal electronic circuitry. Some machines, such as the ones used by the military, have additional features such as a plugboard.

![Parts of Enigma](/blog/assets/img/enigma/partsOfEnigma.jpg)
Encoded messages would be a particular scramble of letters on a given day that would would translate to a comprehendible sentence when unscrambled.

When a key on the keyboard is pressed, one or more rotors move to form a new rotor configuration which will encode one letter as another. Current flows through the machine and lights up one display lamp on the lamp board, which shows the output letter. So if the "K" key is pressed, and the Enigma machine encodes that letter as a "P," the "P" would light up on the lamp board.

Each month, Enigma operators received codebooks which specified which settings the machine would use each day. Every morning the code would change.

For example, one one day, the codebook may list the settings described in the day-key below:

1\. Plugboard settings: A/L – P/R – T/D – B/W – K/F – O/Y

A plugboard is similar to an old-fashioned telephone switch board that has ten wires, each wire having two ends that can be plugged into a slot. Each plug wire can connect two letters to be a pair (by plugging one end of the wire to one letter’s slot and the other end to another letter). The two letters in a pair will swap over, so if “A” is connected to “Z,” “A” becomes “Z” and “Z” becomes “A.” This provides an extra level of scrambling for the military.

To implement this day-key first you would have to swap the letters A and L by connecting them on the plugboard, swap P and R by connecting them on the plugboard, and then the same with the other letter pairs listed above. Essentially, a one end of a cable would be plugged into the "A" slot and the other end would be plugged into the L slot. Before any further scrambling happens by the rotors, this adds a first layer of scrambling where the letters connected by the cable are encoded as each other. For example, if I were to encode the message `APPLE` after connecting only the "A" to the "L", this would be encoded as `LPPAE`.

![Plugboard](/blog/assets/img/enigma/plugboard.jpg)

2\. Rotor (or scrambler) arrangement: 2 — 3 —1

The Enigma machines came with several different rotors, each rotor providing a different encoding scheme. In order to encode a message, the Enigma machines took three rotors at a time, one in each of three slots. Each different combination of rotors would produce a different encoding scheme. Note: most military Enigma machines had three rotor slots though some had more.

To accomplish the configuration above, place rotor #2 in the 1st slot of the enigma, rotor #3 in the 2nd slot, and rotor #1 in the 3rd slot.
![Enigma wheels within alphabet rings in position in an Enigma scrambler](/blog/assets/img/enigma/rotor.jpg)

## Enigma Encryption

As mentioned in above sections, Enigma uses a form of substitution ciphers.

Each of the three rotors will display a number or letter (the rotors in the image above have letters), and when the rotors turn, a new set of three numbers/letters appears. With the initial set of three numbers/letters (meaning the numbers/letters on the sender’s machine when they began to type the message), a message recipient can decode the message by setting their (identical) Enigma machine to the initial settings of the sender’s Enigma machine. Each rotor has 2626 numbers/letters on it. An Enigma machine takes three rotors at a time, and the Germans could interchange rotors, choosing from a set of five, resulting in thousands of possible configurations. For example, one configuration of rotors could be: rotor #5 in slot one, rotor #2 in slot two, and rotor #1 in slot three.

## Cracking the Enigma Code

A major flaw with the Enigma code was that a letter could never be encoded as itself. In other words, an “M” would never be encoded as an “M.” This was a huge flaw in the Enigma code because it gave codebreakers a piece of information they could use to decrypt messages. If the codebreakers could guess a word or phrase that would probably appear in the message, they could use this information to start breaking the code. Because the Germans always sent a weather report at the beginning of the message, and usually included the phrase “Heil Hitler” at the end of the message, there were phrases decrypters knew to look for. Decoders could compare a given phrase to the letters in the code, and if a letter in the phrase matched up with a letter in the code, they knew that that part of the code did not contain the phrase. The decoders could then begin cracking the code with a process of elimination approach.

### Example

**_Find possible contenders for the encoding of the word “RAIN” in the coded string below_**

![table](/blog/assets/img/enigma/ex2-1.png)

RAIN cannot be encoded as ERWN because the N in RAIN and the N in ERWN match up. Since N cannot be encoded as itself, this isn’t the encoding.

Let’s shift our message one slot to the right, and see if the result is a valid encoding.
![table](/blog/assets/img/enigma/ex2-2.png)

RAIN cannot be encoded as RWNI because the R in RAIN matches with the R in RWNI. Let’s shift again.
![table](/blog/assets/img/enigma/ex2-3.png)

RAIN cannot be encoded as WNIK because the I in RAIN matches with the I in WNIK.
![table](/blog/assets/img/enigma/ex2-4.png)

RAIN can be encoded as NIKO because the two phrases have no letters that match up. So NIKO is a possible encoding of RAIN.

If we repeat this process, we will find that NIKO, IKOL, KOLK, OLKM, LKMM, KMMM, and MMMM are all possible encodings of RAIN since no letters match up between RAIN and the encoding. It is okay that MMMM could encode RAIN even though this means that M would encode R, A, I, and N because remember that at each key press, the letter mapping in an Enigma machine changes.

It is not guaranteed that RAIN is encoded in this string at all, though, but it gave decoders a good starting point for decrypting messages.

Alan Turing and Gordon Welchman designed a machine called the Bombe machine which used electric circuits to solve an Enigma encoded message in under 20 minutes. The Bombe machine would try to determine the settings of the rotors and the plugboard of the Enigma machine used to send a given coded message.

The standard British Bombe machine was essentially 36 Enigma machines wired together, this way, the Bombe machine would simulate several Enigma machines at once. Most Enigma machines had three rotors and to represent this in the Bombe, each of the Enigma simulators in the Bombe had three drums, one for each rotor.
bombeMachineDrums

![Bombe machine drums](/blog/assets/img/enigma/bombeMachineDrums.jpg)

The Bombe's drums were color coded to correspond with which rotor they were simulating. While an 3-rotor Enigma machine only used three rotors at a time, there are more to choose from. The drums were arranged so that the top one of the three simulated the left-hand rotor of the Enigma scrambler, the middle one simulated the middle rotor, and the bottom one simulated the right-hand rotor. The drums would turn to try out a new configuration. For each full rotation of the top drums, the middle drums were incremented by one position, and likewise for the middle and bottom drums, giving the total of 26 × 26 × 26 = 17,576 positions of the 3-rotor Enigma scrambler.

Then, for a given rotor configuration (at each turn of the drums), the Bombe machine would make a guess about a plugboard setting, say “A is connected to Z.” It then ran through and determined what all of the other letters must be set to on the plugboard. If any contradictions arose, say, it deduced that “A was connected to W,” then it must be that A is not connected to Z on the plugboard, a contradiction arises. Since the other letter mappings the machine just figured out were determined based off of a false assumption (namely the assumption that A is connected to Z), all of those combinations are invalid, and the Bombe machine knows not to waste time checking any of those combinations later. So, say that the machine guessed that A is connected to Z, and then the machine deduces that if A is connected to Z, then B must be connected to E. If it later determines that A is not connected to Z, it knows that B is not connected to E. After such a contradiction arises, the Bombe machine will not guess that A is connected to Z again, and it knows not to guess that B is connected to E, and so on. The Bombe machine shifts the rotor positions, and chooses a new guess and repeats this process until a satisfying arrangement of settings appears. Because electric circuits can perform computations very quickly, the Bombe machine can go through all the rotor combinations in about 20 minutes.

At each position of the drums, the configuration would be tested to see if the configuration lead to a logical contradiction, ruling out that setting. If the test did not lead to a contradiction, the machine would stop and the decoder would note that configuration as a candidate solution. Then, the machine is restarted and more configurations are tested. These tests would narrow down the list of possible configurations and the candidate solutions would be tested further to eliminate ones that wouldn't work. There were usually many unsuccessful candidate solutions before the correct one was found.

## References

1. Nassiri, A. _Enigma (crittografia) - Museo scienza e tecnologia Milano_. Retrieved April 30, 2016, from [https://en.wikipedia.org/wiki/File:Enigma*(crittografia)*-\_Museo_scienza_e_tecnologia_Milano.jpg](<https://en.wikipedia.org/wiki/File:Enigma_(crittografia)_-_Museo_scienza_e_tecnologia_Milano.jpg>)
2. , C. _Caesar3_. Retrieved April 30, 2016, from [https://commons.wikimedia.org/wiki/File:Caesar3.svg](https://commons.wikimedia.org/wiki/File:Caesar3.svg)
3. Sperling, K. _EnigmaMachineLabeled_. Retrieved April 30, 2016, from [https://en.wikipedia.org/wiki/File:EnigmaMachineLabeled.jpg](https://en.wikipedia.org/wiki/File:EnigmaMachineLabeled.jpg)
4. Lord, B. _Enigma-plugboard_. Retrieved April 30, 2016, from [https://en.wikipedia.org/wiki/File:Enigma-plugboard.jpg](https://en.wikipedia.org/wiki/File:Enigma-plugboard.jpg)
5. , M. _File:Enigma-rotor-windows.jpg_. Retrieved July 20, 2016, from [https://commons.wikimedia.org/wiki/File:Enigma-rotor-windows.jpg](https://commons.wikimedia.org/wiki/File:Enigma-rotor-windows.jpg)
6. , T. _Enigma rotors with alphabet rings_. Retrieved April 30, 2016, from [https://en.wikipedia.org/wiki/File:Enigma_rotors_with_alphabet_rings.jpg](https://en.wikipedia.org/wiki/File:Enigma_rotors_with_alphabet_rings.jpg)
7. , N. _158,962,555,217,826,360,000 (Enigma Machine)_. Retrieved April 28, 2016, from [https://www.youtube.com/watch?v=G2_Q9FoD-oQ](https://www.youtube.com/watch?v=G2_Q9FoD-oQ)
8. , N. _Flaw in the Enigma Code_. Retrieved April 28, 2016, from [https://www.youtube.com/watch?annotation_id=annotation_786414&amp;feature=iv&amp;src_vid=G2_Q9FoD-oQ&amp;v=V4V2bpZlqx8](https://www.youtube.com/watch?annotation_id=annotation_786414&feature=iv&src_vid=G2_Q9FoD-oQ&v=V4V2bpZlqx8)
9. , T. _File:Rotating upper bombe drum.jpg_. Retrieved July 21, 2016, from [https://en.wikipedia.org/wiki/File:Rotating_upper_bombe_drum.jpg](https://en.wikipedia.org/wiki/File:Rotating_upper_bombe_drum.jpg)
10. , . _Bombe_. Retrieved July 21, 2016, from [https://en.wikipedia.org/wiki/Bombe](https://en.wikipedia.org/wiki/Bombe)
Binary file added assets/img/authors/Inbasekaran.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/bombeMachineDrums.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/caesarCipher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/caesarCipherExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/enigma - Shortcut.lnk
Binary file not shown.
Binary file added assets/img/enigma/enigmaMachine.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/ex2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/ex2-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/ex2-2c3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/ex2-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/ex2-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/partsOfEnigma.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/plugboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/enigma/rotor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.