# Enigma Machine rotors math

I have been doing a study about the enigma machine for the past weeks. I managed to get ahold of the formulae used in "Cryptography, Information theory and error-correction" book for the enigma machine coding calculations.

I am aware that when the electrical signal travels towards the reflector the susbtitutions of the rotors can be represented by:

• b = Rem[a+r1, 26]^α1
• c = Rem[b+r2, 26]^α2
• d = Rem[c+r3, 26]^α3

The reflector by:

• e = (d)^β

And when the signal travels to the keyboard the formulae are inverted:

• c' = Rem[e^(α3^-1) - r3, 26]
• b' = Rem[c'^(α2^-1) - r2, 26]
• a' = Rem[b'^(α1^-1) - r1, 26]

I am using the numeric alphabet from 0 to 25, the rotors III left, II middle and I right with the permutations

• Rotor I (α1): (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S)
• Rotor II (α2): (A) (BJ) (CDKLHUP) (ESZ) (FIXVYOMW) (GR) (NT) (Q)
• Rotor III (α3): (ABDHPEJT) (CFLVMZOYQIRWUKXSG)(N)
• Reflector B (β): (AY) (BR) (CU) (DH) (EQ) (FS) (GL)(IP) (JX) (KN) (MO) (TZ) (VW)

And the initial settings: "D", "O", "I" (r1=8, r2=14, r3=3). When I try to code the letter "L" this is what I get:

• Rem["L"+ 8, 26]^α1 = "P"

• Rem["P"+ 14, 26]^α2 = "K"

• Rem["K"+ 3, 26]^α3 = "N"

• ("N")^β = "K"

• Rem["K"^(α3^-1) - 3, 26] = "R"

• Rem["R"^(α2^-1) - 14, 26] = "S"

• Rem["S"^(α1^-1) - 6, 26] = "K"

I checked in multiple enigma machine simulators and the correct output with the same settings is "V". Can anyone explain me why?

• Did you apply the (inverse) keyboard, too? Commented Mar 26, 2021 at 17:38
• What is the (inverse) keyboard? Commented Mar 27, 2021 at 13:01
• There is a permutation on the keyboard, too. Commented Mar 27, 2021 at 13:03
• I am assuming the plugboard has no connections if that's what you mean. Commented Mar 27, 2021 at 14:29

There are three small mistakes. The first two are related. Along the outward signal path, you are absolutely right to change the value by +r1 before entering the wire core of rotor α1. It translates the input from the global coordinate system of the whole machine to the local coordinate system of the wiring core of α1. However, after exiting the wiring core and before exiting the rotor itself, you will need to translate it back to the global coordinate system by -r1. The third mistake is the mix up between the starting indicator and the indicator shown after a key is pressed.

## Machine setup

• On the right, there is Rotor I. α1 = (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S)
• In the middle, there is Rotor II. α2 = (A) (BJ) (CDKLHUP) (ESZ) (FIXVYOMW) (GR) (NT) (Q)
• On the left, there is Rotor III. α3 = (ABDHPEJT) (CFLVMZOYQIRWUKXSG)(N)
• On the far left, there is Reflector B. β = (AY) (BR) (CU) (DH) (EQ) (FS) (GL) (IP) (JX) (KN) (MO) (TZ) (VW)
• Plugboard is not used.
• Ring setting is 01 01 01 (A A A)
• Starting indicator shown through the windows is D O I (04 15 09). And hence, r3=3, r2=14 and r1=8.

## The correct formulae

The correct formulae along the outward signal path are,

• b = Rem[ Rem[a + r1, 26]^α1 - r1, 26]
• c = Rem[ Rem[b + r2, 26]^α2 - r2, 26]
• d = Rem[ Rem[c + r3, 26]^α3 - r3, 26]
• e = (d)^β

Regardless if it is the outward path or the return path, the wiring cores are offset by the same amounts with respect to the global coordinate system. Therefore, we have,

• c' = Rem[ Rem[e^(α3^-1) + r3, 26] - r3, 26]
• b' = Rem[ Rem[c'^(α2^-1) + r2, 26] - r2, 26]
• a' = Rem[ Rem[b'^(α1^-1) + r1, 26] - r1, 26]

## Before any key is pressed

At time t=0, when your machine is set up, starting indicator shown through the windows is D O I (04 15 09). However, you don't care about this one, since no key has been pressed. If there were a circuit, the following listing would have been the circuit path for letter "L". I need to emphasise "were", since there is no complete circuit at this point.

L > L 12+8=20 T > P 16-8=8,
8+14=22 V > Y 25-14=11,
11+3=14 N > N 14-3=11 K >> N
14+3=17 Q > Y 25-3=22,
22+14=10 J > B 2-14=14,
14+8=22 V > I 9-8=1 A > A


## During and after letter "L" is pressed

At time t=0.5, letter "L" is pressed halfway down, right rotor α1 advances by one place and indicator is now D O J (04 15 10) and hence r3=3, r2=14 and r1=9. At time t=1 (it is also the character at position 1 of the ciphertext/plaintext), press and hold key "L" all the way down. There is a complete circuit. Therefore, we have,

• a = "L"
• b = Rem[ Rem["L" + 9, 26]^α1 - 9, 26] = "R" (18)
• c = Rem[ Rem["R" + 14, 26]^α2 - 14, 26] = "U" (21)
• d = Rem[ Rem["U" + 3, 26]^α3 - 3, 26] = "P" (16)
• e = ("P")^β = "I" (09)
• c' = Rem[ Rem["I"^(α3^-1) + 3, 26] - 3, 26] = "C" (03)
• b' = Rem[ Rem["C"^(α2^-1) + 14, 26] - 14, 26] = "C" (03)
• a' = Rem[ Rem["C"^(α1^-1) + 9, 26] - 9, 26] = "V" (22)

The last line shows that output is a' = "V". Below is my screen dump.

L > L 12+9=21 U > A 1-9=18,
18+14=6 F > I 9-14=21,
21+3=24 X > S 19-3=16 P >> I
9+3=12 L > F 6-3=3,
3+14=17 Q > Q 17-14=3,
3+9=12 L > E 5-9=22 V > V