Class EnigmaMachine

java.lang.Object
  extended by EnigmaMachine

public class EnigmaMachine
extends java.lang.Object

The class EnigmaMachine implements an enigma machine with three rotors known as enigma machine M3. It is comprised of one plugboard, 3 rotors (out of 5 types of rotors) and one reflector (out of two types of reflectors). Below we call the Right, Middle and Left rotors as rotor1, rotor2 and rotor3, respectively.

Author:
Lucia Moura

Constructor Summary
EnigmaMachine()
          A constructor of arity 0 that sets the machine to default values: rotors RML are types I, II, III, reflector is type B rotor positions AAA
EnigmaMachine(int rotor1Type, int rotor2Type, int rotor3Type, int reflectorType)
          A constructor of arity 4 that sets the machine to given rotor and refletor types; rotor positions set to default values AAA.
EnigmaMachine(int rotor1Type, int rotor2Type, int rotor3Type, int reflectorType, char startPos1, char startPos2, char startPos3)
          A constructor of arity 7 that sets the machine to given rotor types, refletor type and rotor positions.
 
Method Summary
 void disableStepping()
          The method disableStepping sets the machine to disallow the rotors stepping.
 void enableStepping()
          The method enableStepping sets the machine to allow the rotors step according to the stepping rules.
 char encrypt(char letter)
          This method encrypt performs the encoding of one letter going through the enigma machine, executing the letter trip through the various machine elements, until it gets encoded as a new output letter that is returned.
 java.lang.String encrypt(java.lang.String text)
          This method encrypt performs the encoding of a whole text going through the enigma machine, by sucessive calling the encoding of each of its individual letters.
 void plug(char letter1, char letter2)
          The method plug plugs the two given letters in the plugboard.
 void resetRotorPositions()
          The method resetRotorPositions brings the rotor positions to their initial rotor position values.
 void setInitialRotorPositions(char letter1, char letter2, char letter3)
          The method setInitialRotorPositions initializes the initial position of the rotors for the next encoding to be as given.
 java.lang.String toString()
          This method overrides java.lang.Object.toString() and returns a string representation of this EnigmaMahine.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnigmaMachine

public EnigmaMachine()
A constructor of arity 0 that sets the machine to default values: rotors RML are types I, II, III, reflector is type B rotor positions AAA


EnigmaMachine

public EnigmaMachine(int rotor1Type,
                     int rotor2Type,
                     int rotor3Type,
                     int reflectorType)
A constructor of arity 4 that sets the machine to given rotor and refletor types; rotor positions set to default values AAA.

Parameters:
rotor1Type - is the type of the right rotor (number 1..5)
rotor2Type - is the type of the middle rotor (number 1..5)
rotor3Type - is the type of the left rotor (number 1..5)
reflectorType - is the type of reflector: 1 is type B, 2 is type C.

EnigmaMachine

public EnigmaMachine(int rotor1Type,
                     int rotor2Type,
                     int rotor3Type,
                     int reflectorType,
                     char startPos1,
                     char startPos2,
                     char startPos3)
A constructor of arity 7 that sets the machine to given rotor types, refletor type and rotor positions.

Parameters:
rotor1Type - is the type of the right rotor (number 1..5)
rotor2Type - is the type of the middle rotor (number 1..5)
rotor3Type - is the type of the left rotor (number 1..5)
reflectorType - is the type of reflector: 1 is type B, 2 is type C.
startPos1 - is the char position of the right rotor.
startPos2 - is the char position of the middle rotor.
startPos3 - is the char position of the left rotor.
Method Detail

enableStepping

public void enableStepping()
The method enableStepping sets the machine to allow the rotors step according to the stepping rules. This should be the default state of the machine.


disableStepping

public void disableStepping()
The method disableStepping sets the machine to disallow the rotors stepping. This is used for testing purposes only so that rotor encoding can be tested independently of the stepping mechanism.


setInitialRotorPositions

public void setInitialRotorPositions(char letter1,
                                     char letter2,
                                     char letter3)
The method setInitialRotorPositions initializes the initial position of the rotors for the next encoding to be as given. Historically in WWW2, rotor and reflector types where changed daily while rotor positions where changed for each message transmitted.

Parameters:
letter1 - is the initial position for the right rotor (rotor1)
letter2 - is the initial position for the middle rotor (rotor2)
letter3 - is the initial position for the left rotor (rotor3)

resetRotorPositions

public void resetRotorPositions()
The method resetRotorPositions brings the rotor positions to their initial rotor position values. This "initial rotor position" is set at machine creation and may have been updated by a former call to setInitialRotorPositions(). This has been provided to facilitate resending the same message or testing the decoding of the last message sent.


plug

public void plug(char letter1,
                 char letter2)
The method plug plugs the two given letters in the plugboard.

Parameters:
letter1 - is a letter to be plugged to the other letter given.
letter2 - is a letter to be plugged to the other letter given.

encrypt

public char encrypt(char letter)
This method encrypt performs the encoding of one letter going through the enigma machine, executing the letter trip through the various machine elements, until it gets encoded as a new output letter that is returned. Note: the stepping of the rotos is done before the character travels through the rotors.

Parameters:
letter - is the input letter (a capital letter from 'A' to 'Z')
Returns:
the output encoded letter (a capital letter from 'A' to 'Z')

encrypt

public java.lang.String encrypt(java.lang.String text)
This method encrypt performs the encoding of a whole text going through the enigma machine, by sucessive calling the encoding of each of its individual letters.

Parameters:
text - is the input text consisting only of capital letters ('A' to 'Z')
Returns:
is the output encoded text

toString

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

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