Class Rotor

java.lang.Object
  extended by Rotor

public class Rotor
extends java.lang.Object

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

Constructor Summary
Rotor(int rotorType)
          A constructor of arity 1 that specifies the rotor type.
Rotor(int rotorType, char startPosition)
          A constructor of arity 2 that specifies the rotor type and initial position.
 
Method Summary
 boolean atNotch()
          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)
 char getCurrentPosition()
          Method getCurrentPosition returns the current letter position of this rotor.
 char getInitialPosition()
          Method getInitialPosition returns the initial position of this rotor.
 char getNotch()
          Method getNotch returns the notch position of the rotor
 java.lang.String getType()
          Return the rotor type.
 java.lang.String getWiring()
          Method getWiring returns the wiring encoding of this rotor
 char outLetter(char inputLetter, boolean forward)
          Method outLetter produces the resulting letter obtained from the the given letter entering one of the sides of the rotor
 void resetRotorPosition()
          Method resetRotorPosition makes the current rotor position to go back to the initial rotor position.
 void setInitialRotorPosition(char letter)
          Method setInitialRotorPosition sets both the rotor initial position and the rotor current position to the given letter.
 void step()
          Method step makes the rotor advance its position by one letter of the alphabet (e.g.
 java.lang.String toString()
          This method overrides java.lang.Object.toString() and returns a string representation of this Rotor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rotor

public Rotor(int rotorType)
A constructor of arity 1 that specifies the rotor type. The rotor position must be set to default initial position 'A'.

Parameters:
rotorType - is a number 1..5 specifying types I..V

Rotor

public Rotor(int rotorType,
             char startPosition)
A constructor of arity 2 that specifies the rotor type and initial position.

Parameters:
rotorType - is a number 1..5 specifying types I..V
startPosition - is a capital letter 'A' to 'Z' specifying the initial rotor position
Method Detail

getType

public java.lang.String getType()
Return the rotor type.

Returns:
the rotor type, a string containing a roman number which is one of " I"," II","III"," IV"," V".

getWiring

public java.lang.String getWiring()
Method getWiring returns the wiring encoding of this rotor

Returns:
a string of 26 letters representing the wiring encoding of this rotor.

getInitialPosition

public char getInitialPosition()
Method getInitialPosition returns the initial position of this rotor.

Returns:
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)

getCurrentPosition

public char getCurrentPosition()
Method getCurrentPosition returns the current letter position of this rotor.

Returns:
the current letter position of this rotor

outLetter

public char outLetter(char inputLetter,
                      boolean forward)
Method outLetter produces the resulting letter obtained from the the given letter entering one of the sides of the rotor

Parameters:
inputLetter - is the letter entering the rotor
forward - specifies the direction of the encoding; true specifies the usual direction and false specifies the opposite direction
Returns:
the letter that comes out of the rotor

step

public void step()
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')


setInitialRotorPosition

public void setInitialRotorPosition(char letter)
Method setInitialRotorPosition sets both the rotor initial position and the rotor current position to the given letter.

Parameters:
letter - is the new value for initial rotor position and current rotor position.

resetRotorPosition

public void resetRotorPosition()
Method resetRotorPosition makes the current rotor position to go back to the initial rotor position.


atNotch

public boolean atNotch()
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)

Returns:
a boolean value indicating if the rotor is currently at its notch position

getNotch

public char getNotch()
Method getNotch returns the notch position of the rotor

Returns:
the notch position of the rotor

toString

public java.lang.String toString()
This method overrides java.lang.Object.toString() and returns a string representation of this Rotor.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this Rotor