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
|
public class Main {
private static char[][] rotor1 = {{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'},
{'G', 'T', 'U', 'B', 'Z', 'Y', 'V', 'J', 'L', 'K', 'S', 'A', 'W', 'X', 'H', 'C', 'D', 'E', 'M', 'N', 'O', 'P', 'Q', 'R', 'I', 'F'}};
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
rotateRotor(rotor1);
}
public static void rotateRotor(char[][] aRotor) {
if (aRotor == null || aRotor.length < 1) {
throw new IllegalArgumentException("invalid rotor");
}
rotateRotor1D(aRotor[0]);
}
public static void rotateRotor1D(char[] aRotor) {
if (aRotor == null || aRotor.length < 1) {
throw new IllegalArgumentException("invalid rotor");
}
char temp = aRotor[0];
for (int i = 0; i < aRotor.length - 1; i++) {
aRotor[i] = aRotor[i + 1];
}
aRotor[aRotor.length - 1] = temp;
}
public static void rotateRotor2D(char[][] aRotor) {
for (int row = 0; row <
aRotor.length; row++) {
char carry = aRotor[row][0];
for (int col = 1; col <
aRotor[row].length; col++) {
aRotor[row][col - 1] = aRotor[row][col];
}
aRotor[row][aRotor[row].length - 1] = carry;
}
}
} |