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
(it will always be an even number)
-
The number of rotors that can be put inside the mechanism : labelled with
R
-
The number of different rotors that can be used : labelled with
X
(
X
≥
R
)
-
The (non)existence of plugboard : labelled with
P
(
P
=
1
plugboard is present;
P
=
0
absent)
-
The ability to rewire reflector : labelled with
A
(
A
=
1
it is rewireable;
A
=
0
not rewireable)
-
Final feature: Cryptographic strength of the Enigma : labelled with
S
It is required to make a program, which will calculate
S
if all other key features are known.
Explanation how
S
is calculated:
-
S
i
basically represents how many different initial settings Enigma model
i
has.
-
So firstly, the operator (
Op
) has
exactly
X
different rotors at disposal and needs to choose
R
rotors from that group.
-
Secondly,
Op
decides in which order the chosen
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
different positions for each rotor.
-
Fourthly, if
A
=
1
,
Op
rewires the reflector. Here,
Op
needs to form
2
K
pairs (each letter must be paired with exactly one other,
one letter cannot be "paired" with itself).
-
Fifthly, if
P
=
1
,
Op
sets the plugboard. For this,
Op
has
2
K
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
)
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
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
=
3
6
0
Link for questions
here
.
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 .
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 objects (rotors), which will be somehow arranged in R designated positions, with guarantee X ≥ R - these are permutations with restriction (if X > R ) or permutations (if 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 ) .
Initial rotation of each rotor (or initial setting of each rotor ): I believe it is obvious that each rotor, having K letters, can be set to K different positions, and having R rotors placed into the machine, that is: K R
Finally the plugboard (since 4. will heavily rely on 3). There are K = 2 × w letters, since 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 } , which represents number of pairs, and this iterator will take each value from the set. Forming first pair is done on ( K 2 ) ways, forming second pair ( K − 2 2 ) , 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 ! is needed. Putting all that in one formula, result is: ∑ j = 0 2 K ( 2 j × j ! × ( K − 2 × j ) ! K ! ) .
Reflector setting - this is basically sub-case from 3. where j = 2 K . Thus, solving this is easier than whole part 3. and the formula is: 2 j × j ! K ! .
The results of each segment are multiplied, and that is the final result. Also, if variable P = 0 , solution for part 3 is 1 instead, the same goes for variable A if zero, then solution for part 4 is 1 . If everything is carefully converted into programming code, the program should generate 3 4 3 0 3 8 6 2 0 as an answer for the given file.