The Enigma Machine

The Enigma Machine is a device used for encryption/decryption of data. The key features of each Enigma model are the following:

  • The number of letters on the keyboard (can be 26, can be more) : labelled with K K (it will always be an even number)
  • The number of rotors that can be put inside the mechanism : labelled with R R
  • The number of different rotors that can be used : labelled with X X ( X R X \ge R )
  • The (non)existence of plugboard : labelled with P P ( P = 1 P = 1 plugboard is present; P = 0 P = 0 absent)
  • The ability to rewire reflector : labelled with A A ( A = 1 A = 1 it is rewireable; A = 0 A = 0 not rewireable)
  • Final feature: Cryptographic strength of the Enigma : labelled with S S

It is required to make a program, which will calculate S S if all other key features are known.

Explanation how S S is calculated:

  • S i S_i basically represents how many different initial settings Enigma model i i has.
  • So firstly, the operator ( Op ) has exactly X X different rotors at disposal and needs to choose R R rotors from that group.
  • Secondly, Op decides in which order the chosen R R rotors will be placed (since the position matters).
  • Thirdly, Op sets initial position of each rotor that is placed in the Enigma, and there are K K different positions for each rotor.
  • Fourthly, if A = 1 A = 1 , Op rewires the reflector. Here, Op needs to form K 2 \frac{K}{2} pairs (each letter must be paired with exactly one other, one letter cannot be "paired" with itself).
  • Fifthly, if P = 1 P = 1 , Op sets the plugboard. For this, Op has K 2 \frac{K}{2} cables at disposal. Op can use as many cables as he/she wants (all, one, none,...). If one cable is used, Op must form one pair (using 2 different letters). If 2 cables are used, Op must form 2 pairs. This analogy continues. Of course, if Op decides not to use cables at all, zero pairs must be "formed".

Find ( i = 1 9 S i ) m o d ( 1 0 9 + 7 ) (\sum _{i=1} ^{9} {S_i}) mod (10^9 + 7) for these 9 models of the Enigma. Their key features are placed into a " table ".


Example:

K e = 4 , R e = 1 , X e = 3 , P e = 1 , A e = 1 K_e = 4, R_e = 1, X_e = 3, P_e = 1, A_e = 1

Plugboard (10): 3 options: no cables (1), one cable (6), two cables (3)

Reflector (3): same logic was applied with Plugboard option with two cables.

Choosing rotors (3): We choose one, there are 3 of them...

Placing rotors (1): There is just one rotor...

Initial settings of rotor (4): There is one rotor, there are 4 (letters) initial positions....

S e = 360 S_e = 360


Link for questions here .


The answer is 343038620.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Milan Milanic
Apr 10, 2017

Solution:

This problem is mix of combinatorics and programming, but some basic knowledge from both are ultimately necessary for successful solving, thus I will leave few links that can be helpful and that will back up my solution.

Links: combinations , permutations and probably this, permutations with restriction .

  1. So let's begin. Let's begin with Rotor placement (step choosing rotors and placing rotors combined), as it can be seen, there are X X objects (rotors), which will be somehow arranged in R R designated positions, with guarantee X R X \ge R - these are permutations with restriction (if X > R X > R ) or permutations (if X = R X = R ), in both case, generalization can be made and it can be said that it can be calculated with the following: ( X X R ) \left( \begin{matrix} X \\ X-R \end{matrix} \right) .

  2. Initial rotation of each rotor (or initial setting of each rotor ): I believe it is obvious that each rotor, having K K letters, can be set to K K different positions, and having R R rotors placed into the machine, that is: K R K^{R}

  3. Finally the plugboard (since 4. will heavily rely on 3). There are K = 2 × w K = 2 \times w letters, since K K is even. As the text of problem states, practically pairs need to be formed, but the trick is, that number of pairs varies as well. Let's introduce j { 0 , 1 , . . . w } j \in \{0, 1, ... w\} , which represents number of pairs, and this iterator will take each value from the set. Forming first pair is done on ( K 2 ) \left( \begin{matrix} K \\ 2 \end{matrix} \right) ways, forming second pair ( K 2 2 ) \left( \begin{matrix} K-2 \\ 2 \end{matrix} \right) , and so on. Since the order of pairing is not important (if we paired letters ab and cd , it is completely irrelevant whether we firstly formed pair ab or cd ), division with j ! j! is needed. Putting all that in one formula, result is: j = 0 K 2 ( K ! 2 j × j ! × ( K 2 × j ) ! ) \sum _{j=0} ^{\frac{K}{2}} { ( \frac{K!}{2^{j} \times j! \times (K - 2\times j)!} ) } .

  4. Reflector setting - this is basically sub-case from 3. where j = K 2 j = \frac{K}{2} . Thus, solving this is easier than whole part 3. and the formula is: K ! 2 j × j ! \frac{K!}{2^{j} \times j! } .

The results of each segment are multiplied, and that is the final result. Also, if variable P = 0 P = 0 , solution for part 3 is 1 1 instead, the same goes for variable A A if zero, then solution for part 4 is 1 1 . If everything is carefully converted into programming code, the program should generate 343038620 \boxed{343038620} as an answer for the given file.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...