Replica Enigma does not give the expected result

I am trying to simulate an Enigma WWII machine in Python code, after some reading on Wikipedia and other dedicated sources. I currently have a machine that scrambles the input text and can return the scrambled output back to the input if the configuration is reset. But the problem is that the code does not produce the expected results from the same configuration as 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 encrypt AAAAAusing the configuration of the rotor and reflector, I find in this list , I get the encrypted text EVRDW, against BDZGO, which is expected.

Since the text is encrypted and can be correctly decrypted, I believe that the error lies somewhere in the explanation of the texts (or in my understanding), but I could not find where my code does not follow the actions of the Enigma machine.

Code Link

+4
source share
1 answer

I think that you forget to transfer from setting the ring to the position of the rotor before transferring the symbol to the next ring, step 4 below. It seems to me that you take into account the acctual rotor encoding and pass this to the next ring. The right way -

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 few examples

For example, using the rotor I (installation of the ring A-01, rotor pos. A)

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

Transfer A to this ring translates to E, after which the rotor and ring rotate

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

so the next A becomes J

, B-02 (.. ), pos A

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

, A K,

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

A E

, A-01, pos B

Starting position
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

A D,

After one rotation
Pos:          ABCDEFGHIJKLMNOPQRSTUVWXYZ

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

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

I

/, 2

- , ( ). , , A, , B B et.c. /,

. , A-01, , A, A , E ( I) E. B-02, , , A, Z- , , J , - , J trasmitted K- ( , K)

. . ( ), . , , - , , / ( )

, , , , .

+4

All Articles