|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectEnigmaMachine
public class EnigmaMachine
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.
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 |
---|
public EnigmaMachine()
public EnigmaMachine(int rotor1Type, int rotor2Type, int rotor3Type, int reflectorType)
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.public EnigmaMachine(int rotor1Type, int rotor2Type, int rotor3Type, int reflectorType, char startPos1, char startPos2, char startPos3)
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 |
---|
public void enableStepping()
enableStepping
sets the machine to allow the
rotors step according to the stepping rules. This should be the
default state of the machine.
public void disableStepping()
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.
public void setInitialRotorPositions(char letter1, char letter2, char letter3)
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.
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)public void resetRotorPositions()
public void plug(char letter1, char letter2)
plug
plugs the two given letters in the
plugboard.
letter1
- is a letter to be plugged to the other letter given.letter2
- is a letter to be plugged to the other letter given.public char encrypt(char letter)
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.
letter
- is the input letter (a capital letter from 'A' to 'Z')
public java.lang.String encrypt(java.lang.String text)
encrypt
performs the encoding of a whole
text going through the enigma machine, by sucessive calling the
encoding of each of its individual letters.
text
- is the input text consisting only of capital letters ('A' to 'Z')
public java.lang.String toString()
EnigmaMahine
.
toString
in class java.lang.Object
EnigmaMahine
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |