Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enigma replica not yielding expected result

I'm trying to mimic the WWII Enigma machine in Python code, following some reading in Wikipedia and other dedicated sources. Currently, I got a machine that scrambles input text and can revert the scrambled output back to input if the configuration is reset. But the problem is the code is not yielding the expected results from the very same configuration that is on Wikipedia:

With the rotors I, II and III (from left to right), wide B-reflector, all ring
settings in A-position, and start position AAA, typing AAAAA will produce the
encoded sequence BDZGO.

If I try to cipher AAAAA using the rotor and reflector configuration I find on this list, I get the ciphered text EVRDW, opposed to BDZGO that is expected.

Since the text is being ciphered and can be deciphered correctly, I believe the mistake is somewhere in the texts' explanation (or my understanding of them), but I couldn't find where my code is not following the operation of an Enigma machine.

Link to the code

like image 915
ranieri Avatar asked Feb 25 '15 06:02

ranieri


People also ask

How did Enigma machine send numbers?

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.

What is Enigma why it is impossible to break?

Enigma was so sophisticated it amounted to what's now called a 76-bit encryption key. One example of how complex it was: typing the same letters together, like "H-H" (for Heil Hitler") could result in two different letters, like "L-N." That type of complexity made the machines impossible to break by hand, Simpson says.

How hard was it to crack the Enigma code?

The complexity of the Enigma Machine is what made the infamous Code so difficult to crack. Using the rotors alone still produced 17,576 possible solutions, let alone the huge number produced when the further encryption level of the plug board was considered.

How many combinations does the Enigma machine have?

Since in the new enigma machine, one extra rotor had been added, which had 26 wired discs. So total possible combinations are 264. To increase the irregularity of the rotational behavior of the rotors, the German Navy used a second notch to some rings in order.


Video Answer


1 Answers

I think you are forgetting to translate from ring setting to rotor position before passing the character to the next ring, step 4 below. It seems to me that you only take into account the acctual rotor encoding and pass that on to the next ring. The proper way is

1) letter comes in
2) translate letter using rotor setting offset
3) translate offest letter using the internal ring wiring to get encoded letter
4) translate encoded letter using the rotor setting (offset)
5) pass offsetted encoded letter to next ring

A couple of examples

For example using Rotor I (ring setting A-01, rotor pos A)

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: ABCDEFGHIJKLMNOPQRSTUVWXYZ
              ||||||||||||||||||||||||||
              EKMFLGDQVZNTOWYHXUSPAIBRCJ

Rotor pos:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

Passsing an A to this ring translates to an E, after this the rotor and ring rotates

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: BCDEFGHIJKLMNOPQRSTUVWXYZA
              ||||||||||||||||||||||||||
              KMFLGDQVZNTOWYHXUSPAIBRCJE

Rotor pos:    BCDEFGHIJKLMNOPQRSTUVWXYZA
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

so next A becomes an J

Now lets mix with ring settings, lets have the ring setting B-02 (i.e. rotated one step) but have the rotor pos in A

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: ZABCDEFGHIJKLMNOPQRSTUVWXY
              ||||||||||||||||||||||||||
              JEKMFLGDQVZNTOWYHXUSPAIBRC

Rotor pos:    ZABCDEFGHIJKLMNOPQRSTUVWXY
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

So first A becomes a K then the ring rotates

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: ABCDEFGHIJKLMNOPQRSTUVWXYZ
              ||||||||||||||||||||||||||
              EKMFLGDQVZNTOWYHXUSPAIBRCJ

Rotor pos:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

so the next A becomes a E

Now lets mix with rotor settings, lets have the ring setting A-01 but have the rotor pos in B

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: ABCDEFGHIJKLMNOPQRSTUVWXYZ
              ||||||||||||||||||||||||||
              EKMFLGDQVZNTOWYHXUSPAIBRCJ

Rotor pos:    BCDEFGHIJKLMNOPQRSTUVWXYZA
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

The first A then yields rotor output D, after rotation the setup is

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

Ring setting: BCDEFGHIJKLMNOPQRSTUVWXYZA
              ||||||||||||||||||||||||||
              KMFLGDQVZNTOWYHXUSPAIBRCJE

Rotor pos:    CDEFGHIJKLMNOPQRSTUVWXYZAB
              ||||||||||||||||||||||||||
              ABCDEFGHIJKLMNOPQRSTUVWXYZ

so the second A yields an rotor output I

A word on the rotor settings

To ensure a correct encryption/decryption you need to make 2 settings on each rotor

  1. rotor offset
  2. ring setting

The rotor offset is simply how the complete rotor is rotated at the start (what letter is shown in the little window). Thus A position means that the rotor has the letter A showing, B position means a B et.c. These are automatically changed during decoding/encoding but needs to be correct when starting otherwise there will be garbage coming out

The rotor setting on the otherhand changes the internal wirings relative to the external connections. So if this is in an A-01 position, then a signal coming in on the external A connection gets routed to the rotors internal A connection and then coded to an E internally (given rotor I) and transmitted on the external E line. If the setting is B-02 that means that a signal coming in on the external A connection gets routed to the rotors internal Z connection and thus coded to a J internally, then due to the setting this J gets trasmitted on the external K connection (thus the next rotor would see a K)

What was confusing for me with this was all the positions. I think of them as external and internal. Each rotor has two external (ingoing and outgoing), these never changes position. Then each rotor has two internal positions, one controlled by the rotor offset and the other by the rotor setting, these are changed at setup of the device and the rotor offset is changed during the encoding/decoding process as part of normal operations (the rotor rotates)

Long explanation, hope it helped more that it hurted and that you get the issue sorted out.

like image 142
Johan Avatar answered Oct 21 '22 22:10

Johan