mozq / dencode-web

Source code of DenCode.
https://dencode.com
Apache License 2.0
69 stars 14 forks source link

Enigma M3: middle rotor II + rigtmost rotors V..VIII produces wrong results #4

Closed Dreamoochy closed 8 months ago

Dreamoochy commented 1 year ago

It seems there is an issue with the roror II in Enigma tool.

Steps to reproduce:

  1. Open Practical Cryptography's Enigma tool
  2. Set the following values:
    Plaintext: SOMESECRETMESSAGE
    key settings: VEZ
    ring settings: ABD
    Rotors: 324
    Plug board settings: GT YC EJ UA RX PN IS WB MH ZV
  3. Press Encrypt/Decrypt
  4. Copy cipertext value to Dencode Enigma tool
  5. Configure Dencode Enigma tool with the above mentioned settings. (Reflector UKW-B)

Result: message is decrypted correctly.

  1. In the Practical Cryptography's Enigma tool set rightmost rotor to 5 (to be 325)
  2. Repeat steps 3-4

Result: message is decrypted incorrectly.

  1. In the Practical Cryptography's Enigma tool set middle rotor to 3 (to be 335)
  2. Repeat steps 3-4

Result: message is decrypted correctly.

So it seems that combinations of the middle rotor II + rightmost rotors V..VIII produce incorrect results.

I've also tested CacheSleuth tool, and it behaves like Practical Cryptography's one, i.e. it has no such issue.

P.S. Thanks to @the-lambda-way

the-lambda-way commented 1 year ago

This also has to do with the position / key settings. If you set the rotors to 325 with positions / key VDZ instead of VEZ, then DenCode agrees with Practical Cryptography. Note that rotor II has a turnover notch at E and rotor V has a notch at Z, so this might be related to this comment on Practical Cryptography. I've noticed issues with many Enigma tools when it comes to double stepping, and I'm not sure what the correct behavior actually is in this special case.

mozq commented 1 year ago

The behavior is certainly different. I implemented Enigma as a separate project. The implementation for double stepping is below.

https://github.com/mozq/enigma4j/blob/d716e97a0cdff6b0fe7544746ccd44836dd6abc6/src/main/java/net/mozq/enigma4j/scrambler/ScramblerChain.java#L131-150

This implementation is based on cryptomuseum.com.

I'll look into it, but if you find anything please let me know.

mozq commented 1 year ago

According to this comment pointed out by @the-lambda-way, the behavior of DenCode seems to be fine. I also checked on Universal Enigma and cryptii, but they are the same as DenCode.

Practical Cryptography's Enigma tool and CacheSleuth use almost the same JavaScript code. Based on the behavior, they may be stepping the middle rotor twice at once.