-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotorConstants.java
executable file
·86 lines (77 loc) · 2.78 KB
/
RotorConstants.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Predefined rotors for Enigma encryption.
* Rotor ciphers are based off of those found in the M3 Enigma Machine.
*
* @author Seth Pollen [email protected]
*/
public class RotorConstants {
/** The number of letters printed on each rotor. */
public static final int ROTOR_LENGTH = 26;
/**
* The cipher strings for each rotor. They store the letter-order
* for each rotor. The rotor at index 0 is the identity rotor.
* The identity rotor will be useful for debugging.
*
* The remaining cipher strings correspond to:
* Rotor I, Rotor II, etc.
*
* <p>Real rotor data was found at:
* http://en.wikipedia.org/wiki/Enigma_rotor_details#Rotor_wiring_tables
*/
public static final String[] ROTORS = {
// Identity Rotor (index 0 - and useful for testing):
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
// Standard Rotors I through VIII:
//00000000001111111111222222
//01234567890123456789012345
"EKMFLGDQVZNTOWYHXUSPAIBRCJ", //I
"AJDKSIRUXBLHWTMCQGZNPYFVOE", //II
"BDFHJLCPRTXVZNYEIWGAKMUSQO", //III
"ESOVPZJAYQUIRHXLNFTGKDCMWB", //IV
"VZBRGITYUPSDNHLXAWMJQOFECK", //V
"JPGVOUMFYQBENHZRDKASXLICTW", //VI
"NZJHGRCXMYSWBOUFAIVLPEKQDT", //VII
"FKQHTLXOCBJSPDZRAMEWNIUYGV", //VIII
//QYHOGNECVPUZTFDJAXWMKISRBL
};
/**
* This is a String constant which represents the letters to be
* printed on the special Reflector rotor. The reflector rotor is placed
* at the end of the stack of other rotors.
*
* It cipher has the special property that every pair of characters
* map to each other.
*/
public static final String REFLECTOR = "QYHOGNECVPUZTFDJAXWMKISRBL";
// To better see the reflection: ABCDEFGHIJKLMNOPQRSTUVWXYZ
/**
* The locations of each rotors' step notches. Each rotor has one or
* two step notches next to particular encoded letters.
*
* When a rotor is turned into the position of its step notch,
* it also causes the next rotor to advance by one position.
*
* <p> Each rotor may have one or more notches.
* This array has a 1-to-1 correspondence with the ROTORS array.
* That is, the rotor in index 0 of ROTORS will correspond to the values
* stored at NOTCHES index 0.
*
* <p>Each rotor may have a different number of notches,
* so this 2D array does not have the same number of elements in
* each sub-array</p>
*/
public static final int[][] NOTCHES = {
// Identity rotor:
{ 0 }, // A
// Standard rotors:
{ 17 }, // Rotor I: notch at R
{ 5 }, // Rotor II: notch at F
{ 22 }, // Rotor III: notch at W
{ 10 }, // Rotor IV: notch at K
{ 0 }, // Rotor V: notch at A
// The last three rotors have two step notches each.
{ 0, 13 }, // Rotor VI: notch at A and N
{ 0, 13 }, // Rotor VII: notch at A and N
{ 0, 13 }, // Rotor VIII: notch at A and N
};
}