matheusportela / enigma-machine

Enigma machine simulator in JavaScript for didactic purposes.
MIT License
37 stars 10 forks source link

Implement double-stepping in middle rotor #1

Closed matheusportela closed 8 years ago

matheusportela commented 8 years ago

Extracted from Technical Details on the Enigma Machine:

The rotors appear to work as a normal odometer, with the right-most rotor always stepping on each key stroke and the other rotors stepping after a complete cycle of the previous rotor, but there is an important difference due to the system of pawls and teeth. The middle rotor will advance on the next step of the first rotor a second time in a row, if the middle rotor is in its own turnover position. This is called the double-step. Below and example of such a sequence when the rotors III – II - I are used:

KDO KDP, KDQ, KER, LFS, LFT, LFU…

As you can observe, stepping from Q to R advances the middle rotor, and on the next step that middle rotor steps again, advancing the third rotor also. This is caused by the mechanical design of pawls and ratchets. There are three pawls that are all three activated on every key stroke. Each pawl is half positioned on the index ring (carrying a notch) of the rotor on its right, and half positioned above the 26 teeth of the rotor on its left (viewed from the point of the operator). A rotor’s ring prevents the pawl from pushing into the teeth of the next-left rotor. When a notch occurs in a ring, the pawl can drop into that notch and push into the teeth of the next-left rotor. Since the right-most pawl is not above an index ring it will continuously advance the right-most rotor.

Once the right-most rotor has stepped and the middle (spring-loaded) pawl can drop down in the right rotor's notch, it will engage the middle rotor's teeth, pushing the middle rotor one step. An identical event will take place when the middle rotor's notch enables the third pawl to drive the teeth of the left-most rotor. A rotor will not only advance if its teeth are catched, but also when a pawl pushes into its notch. This situation creates a double-step of the middle rotor: the right rotor steps and the middle pawl takes the middle rotor one step further. If the middle rotor has moved by this step into its own notch position, then, on the next step, the left-most pawl catches the teeth of the left-most rotor, but the same pawl also pushes in the middle rotor's notch, moving it a second time in a row. Note that a double notched rotor in the middle position will also have two double steps.