top of page

Ideas Portal

Hopping from one bulb to another...

Enigma Machine




Intro


The Enigma Machine is originally invented by a German Engineer : Arthur Scherbius. The Enigma Machine was originally meant for Banks for encrypting and decrypting secret messages or notes.


During WW2, the Nazis saw the Enigma Machine and decided to use the machine, but they also decided to add more parts to make it more complex and secure.







What are the different Parts ?


A military grade Enigma Machine is made from :

  • a Keyboard

  • a Lampboard

  • a Plugboard (added by the Nazis)

  • 3 rotors

  • 1 reflector



Keyboard


an array of 26 switches to complete the circuit,


user uses this to enter the plaintext or ciphertext.

Lampboard


an array of 26 bulbs, when a circuit is completed when a key is pressed,


it shows the encryption or decryption the plaintext or ciphertext

Plugboard


an array of 26 sockets, added by the Nazis


where the user have to make 10 pairs of 2 sockets by connecting 2 letters with a wire


Thats 26!/6!/10!/2^10 = 150738274937250 ways


Rotors


consist of 3 parts :

26 Left Studs,

26 Cross Wires,

26 Right Studs.


If you still remember your kindergarten / primary school days, one of the exersize is "Matching pairs", every item on the left is connected to an item on the right, via a line in the middle. The same thing happens here : every stud on the left are connected to a stud on the right via a wire


In the original version, there are only 3 rotor slots and 3 rotors, so there are 3! = 6 ways to put 3 rotors in a line.


For the military version, there are 3 rotor slots and 5 rotors, so there are 5P3 = 60 ways to put 3 rotors in a line


For the extreme military version, thats 4 rotor slots and 8 rotors, that 8P4 = 1680 ways

Reflector


it is like a rotor, but it only has 26 Left Studs and 13 Cross Wires, no right studs, instead the Left studs are made into 13 pairs via those 13 Cross Wires.







Mechanism : How it works


What the Enigma Machine actually doing during encryption and decryption is creating different sets of 13 pairs from the 26 letters chaotically (but deterministic) for each character in a plaintext or ciphertext.


In cryptography, every algorithm needs what we call a "key" to lock and unlock messages. In this case, based on the way the Enigma Machine is setup, the plaintext or ciphertext that it produce will be different. This means that the way the Machine is setup is the key of the message.


When a key is pressed, the switch of that letter closes (connects), current from the battery flows through, to the plugboard, into the 1st rotor, 2nd rotor, 3rd rotor, then the reflector, and back to the 3rd rotor, 2nd rotor, 1nd rotor, back to the plugboard, to the lampboard and one bulb lights up, and finally back to the battery.




Here Jared Owen created a perfect animation dissecting the entire machine :





And every time when a key is pressed, the 3rd rotor will rotate by one place, this means that the 13 pairs are now different everytime. When the 3rd rotor does 1 revolution, the 2nd rotor rotes by 1 place, when the 2nd rotors does 1 full turn, it kick the 1st rotor by one place.


This is like counting in base 26 :


0,0,0

0,0,1

0,0,2

0,0,3

...

0,0,24

0,0,25

0,1,0

0,1,1

0,1,2

...

0,2,25

0,3,0

...

0,25,25

1,0,0

1,0,1

...

25,25,25

0,0,0

Caesar Cipher vs Enigma Cipher


In Caesar Cipher, the same letter will always encrypted or decrypted to the same letter. if an "A" becomes to an "E" at some point, then all "A" becomes "E"


In Enigma Cipher, the same letter will be something different everytime, "AAAAA" might become "XKLEF", which makes it harder to break.




And because 2 letters are paired, when one letter is the plaintext, the other is the ciphertext, vice versa.




Here is a video from Numberphile talking about it :







The flaw


Because the Enigma Machine is making 13 pairs from the 26 letters, it is guaranteed that a letter can never be encrypted or decrypted to itself. This means that we can start guessing what the users usually sends and check if it is true by checking if there are no letters becoming itself.



Example :


You know your opponent loves weird criminal food combinations with spaghetti, assume that you evedropped the following cipher text :


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC


since you know your opponent likes to mess with spaghetti, it would be a good idea to slide the word "Spaghetti" and see if it fits somewhere :


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC

SPAGHETTI


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC

-SPAGHETTI


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC

--SPAGHETTI


...


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC

----------------SPAGHETTI


LPAMPQHXTIEPISATEGSFHTAPEJSTESATEGXPTAC

-----------------SPAGHETTI


And it seems like it fits there perfectly, and now you can start guessing other possible food items and see how does it fits.


fun stuff : the original plaintext is :

kitkatxonxtopxofxspaghettixwithxnutella







Upgrading the Machine


Back in 2013 when Numberphile made that video, I dived myself into the world of cryptography, and try to fix the flaw "a letter can never become itself". The main idea is to abandon the idea of making pairs from the alphabet, instead what the machine should do is to make a one to one function mapping from one set of alphabet to another set of alphabet, and the mapping changes everytime.




1st attempt : Table

My first attempt is to create a huge table which may look something like this :


(for simplifying the situation, let's assume that the entire alphabet only has 4 letters : ABCD, but you can expand this to 26 letters)

PlainText \ Rotor Position

0

1

2

3

A

A

D

A

B

B

D

C

C

A

C

B

A

B

D

D

C

B

D

C




2nd attempt : Ring Walking

Taking inspiration of rotors, this time I have a rotating mechanism as well. instead of cross wires, we have values instead, assume we have a rotor with 26 numbers :

0 1 3 2 5 -2 -3 4 0 2 ... 5


say we have a signal going in to position 3 (counting from 0)


V

0 1 3 2 5 -2 -3 4 0 2 ... 5


it points at a value of 2, so the rotor rotates by 2 places


       V

-3 5 0 1 3 2 5 -2 -3 4 0 2 ...


and so the signal out puts from position 3(inpos) + 2(click) = 5(outpos)


A key here is that during decryption, the rotor rotates in the opposite direction


And I considered this a successful mechanism.




3rd attempt : why 26 letters only ?


instead of 26 letters, I went for 64 letters, and from the left to right, we have a keyboard, a plugboard, rotor1, rotor2, rotor3, rotor4, and another plugboard, then a lampboard, which resembles a function mapping from the keyboard to the lampboard. This is also known as the "64 Key Enigma Machine"





4th attemp : why 4 rotors and 2 plugboards ?


After learning C++, I decided to break the rigid structure and decided to let the users "construct" there own during run time. And so I came up with "XKey Enigma Machine"





5th attemp : faking C++ in Javascript


Turns out not everyone knows how to download a repository on Github and compile the program, so I decided to bring XKey Enigma Machine from C++ into Javascript, still it is a "console like interface" but it will get the job done.



What are some of the crazy parts ?

  • any number of characters

  • any number of rotors and plugboards (a plugboard is a rotor that doesn't rotate)

  • custom rotor and plugboard wiring editing

  • custom rotor rotation direction, and kickValue (for every n charracters pressed, it will rotate by 1 place)

  • custom rotor-plugboard arrangement

Comments


bottom of page