/**
* A Rotor
is a rotating part of an EnigmaMachine
.
* This implementation provides 5 types of rotors which will be referred as
* 1, 2, 3, 4, 5 representing the wirings of rotor types I, II, III, IV, V
* used in the enigma M3 machine. Each rotor type has a specific wiring
* which represents a permutation and determines to which letter an
* incoming letter will be encoded to. As the Rotor
steps,
* it changes the "rotor position" and so the position of the incoming
* letter with respect to the rotor wiring. The stepping of the rotor
* is controlled via calls to the method step
and affects
* the current rotor position.
*
* @author Lucia Moura
*
*/
public class Rotor {
/**
* A class constant providing an array with the 5 types of
* wiring options. Wiring options at positions 0..4 correspond
* to the wirings of rotor types I..V
* Please do not change this constant declaration!
*/
private final static String[] WIRING_OPTION = {
"EKMFLGDQVZNTOWYHXUSPAIBRCJ",
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"BDFHJLCPRTXVZNYEIWGAKMUSQO",
"ESOVPZJAYQUIRHXLNFTGKDCMWB",
"VZBRGITYUPSDNHLXAWMJQOFECK"
};
/**
* A class constant providing an array with the notch positions
* for the corresponding 5 types of wiring options.
* Notch position at positions 0..4 correspond the notch of rotor types I..V
* Please do not change this constant declaration!
*/
private final static char[] NOTCH_POSITION = {'R','F','W','K','A'};
// ADD YOUR PRIVATE VARIABLES HERE
/**
* A constructor of arity 1 that specifies the rotor type.
* The rotor position must be set to default initial position 'A'.
*
* @param rotorType is a number 1..5 specifying types I..V
*/
public Rotor(int rotorType) {
this(rotorType,'A');
}
/**
* A constructor of arity 2 that specifies the rotor type
* and initial position.
*
* @param rotorType is a number 1..5 specifying types I..V
* @param startPosition is a capital letter 'A' to 'Z' specifying
* the initial rotor position
*/
public Rotor(int rotorType, char startPosition) {
// ADD YOUR CODE HERE
}
/**
* Return the rotor type.
* @return the rotor type, a string containing a roman number which
* is one of " I"," II","III"," IV"," V".
*/
public String getType() {
// ADD YOUR CODE HERE
//it is now incorrectly always returning ?
return "?";
}
/**
* Method getWiring
returns the wiring encoding of this rotor
* @return a string of 26 letters representing the wiring encoding of this rotor.
*/
public String getWiring() {
// ADD YOUR CODE HERE
// it is now incorrectly always returning wiring that does not
// scramble
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
/**
* Method getInitialPosition
returns the initial position
* of this rotor.
* @return the initial position of this rotor (which is the initial
* position when it was creation or the one given by a call
* to setInitialRotorPosition, whichever was last)
*/
public char getInitialPosition() {
// ADD YOUR CODE HERE
//it is now incorrectly always returning W
return 'W';
}
/**
* Method getCurrentPosition
returns the current letter
* position of this rotor.
* @return the current letter position of this rotor
*/
public char getCurrentPosition() {
// ADD YOUR CODE HERE
//it is now incorrectly always returning W
return 'W';
}
/**
* Method outLetter
produces the resulting letter obtained
* from the the given letter entering one of the sides of the rotor
*
* @param inputLetter is the letter entering the rotor
* @param forward specifies the direction of the encoding; true specifies
* the usual direction and false specifies the opposite direction
* @return the letter that comes out of the rotor
*/
public char outLetter(char inputLetter, boolean forward) {
// ADD YOUR CODE HERE
//it is now incorrectly always returning letter A
return 'A';
}
/**
* Method step
makes the rotor advance its position by one
* letter of the alphabet (e.g. if its position was 'A' after stepping
* it becomes 'B' and if it was 'Z' after stepping it becomes 'A')
*/
public void step() {
// ADD YOUR CODE HERE
}
/**
* Method setInitialRotorPosition
sets both the rotor
* initial position and the rotor current position to the given letter.
*
* @param letter is the new value for initial rotor position and current
* rotor position.
*/
public void setInitialRotorPosition(char letter) {
// ADD YOUR CODE HERE
}
/**
* Method resetRotorPosition
makes the current rotor
* position to go back to the initial rotor position.
*/
public void resetRotorPosition() {
// ADD YOUR CODE HERE
}
/**
* Method atNotch
indicates whether the current rotor position
* is at the rotor notch (a special position that may make a rotor next
* to this to step)
*
* @return a boolean value indicating if the rotor is currently at its
* notch position
*/
public boolean atNotch() {
// ADD YOUR CODE HERE
//it is now incorrectly always returning false
return false;
}
/**
* Method getNotch
returns the notch position of the rotor
* @return the notch position of the rotor
*/
public char getNotch() {
// ADD YOUR CODE HERE
//it is now incorrectly always returning letter Y
return 'Y';
}
/**
* This method overrides java.lang.Object.toString() and
* returns a string representation of this Rotor
.
*
* @return a string representation of this Rotor
*/
public String toString() {
// here we have provided a standard output format uniform for
// all students; please do not alter this format.
return "Rotor type "+ getType()+", Wiring:"+ getWiring()
+", Notch:"+ getNotch()
+", Initial position: "+getInitialPosition()
+", Current position: "+getCurrentPosition();
}
};