Thursday, January 21, 2016

Encryption in World War 2: The Wheelset


Have you ever wondered how some of the German WWII ciphers worked? After reading a couple books on the subject I decided to write an encryption program based on the spirit of the WWII Tunny (fish) ciphers. This is modern interpretation based on the German Lorenz cipher machine, and I primarily did this to teach myself more about the process.


Tunny was a binary cipher, all input was converted to ones and zeros. It was also transmitted (in binary) using electronic machines. There were no human radio operators for Tunny which was unlike Enigma which was not binary and was transmitted by radio operators sending alphabetic characters.

Today's post is an introduction to the wheels and setting up a wheelset. The German machines had a series of wheels that rotated. Each wheel was covered with random bits, and that random data was combined with the letters producing encrypted messages. Each time a letter was enciphered one or more wheels changed locations which changed the random data.

Here is a simple two wheel example. Wheel A is set in location 2 which has a value of 149. Wheel B is set in location 4 which has a value of 203. As the wheels turn in a virtual way they change locations providing a combination of pseudo-random values.

Loc
Wheel A
Loc
Wheel B
0
93
0
11
1
27
1
41
->
2
149
2
165
3
161
3
76
4
30
->
4
203
5
89
6
54

 

A good question that I pondered was how many wheels to have. This is primarily for teaching, so I didn't feel like I need 12 wheels. The starting location of the wheels is a type of message key for the cipher. So it's useful to look at an example of how the number of wheels affects the strength of the message cipher.

Let's say that we have 120 numbers to partition out amongst an undecided number of wheels. If we created two wheels each one could have 60 numbers, if three wheels each could have 40 and so on. Below I built a table showing the number of possible starting key combinations for some example setups.

Number of wheels
Size of wheel
Key Combinations
1
120
120
2
60
3,600
3
40
64,000
4
30
810,000
5
24
7,962,624
10
12
61,917,364,224
20
6
3.65616E+15
60
2
1.15292E+18

 

As you can see, even though we cap the total numbers, choosing a higher number of wheels significantly increases the complexity of your key. For this example program I decided that 4 wheels would provide enough complexity to give some good examples. If I was a little more serious I would increase the wheel count to 8 and the number count to something larger like 240. Even then my program would not have a very powerful key, the security of the program would be less in the key, and more in the wheelset. As long as no one got the 240 numbers in your wheelset you would be relatively safe sending a lot of short messages.

With the original machine, the wheels were physical and had to be replaced to introduce a new set of random values, but with my program I can readily regenerate the wheelset when needed. But remember that both parties need to securely exchange the wheelset before they start sending messages.

Below is an example of the program. Notice that there are 4 wheels in the Daily Wheel Key. Each day all participants would set the starting value to a predetermined setting. Notice that this method requires the users to share keys and the wheels before they go their separate ways and start sending messages. In WWII there were hundreds of navel vessels and army outposts that all had matching codebooks with daily keys that had to be kept safe or the messages would be at risk.


Things to Try:

  • Enter a message and encrypt it. Copy the xml output to the input field and decrypt.
  • Change a key setting when decrypting and verify that you can't decrypt if the settings have changed.
  • Encrypt the message "pppppp" and notice that each letter translates to a completely different number. This is not a cryptogram where all letters map to the same thing.

No comments:

Post a Comment