mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-11-25 22:02:07 +01:00
There is a bug in (I think) the turnover of the rotors. But I am working on that!
This commit is contained in:
parent
d9e3ce5b2b
commit
664f77fe9c
2 changed files with 13 additions and 6 deletions
Binary file not shown.
|
@ -39,7 +39,9 @@ public class Rotor
|
||||||
//Atributes of the rotor
|
//Atributes of the rotor
|
||||||
private Integer[] rotor; //choose one of rotor1-5
|
private Integer[] rotor; //choose one of rotor1-5
|
||||||
private Integer[] rrotor; //choose one of backwardsRotor1-5
|
private Integer[] rrotor; //choose one of backwardsRotor1-5
|
||||||
private int ringsetting; //TODO: Add functionality to this.
|
private int ringsetting; //http://people.physik.hu-berlin.de/~palloks/js/enigma/enigma-u_v20.html
|
||||||
|
//My fault?
|
||||||
|
private int turnOver;
|
||||||
private int counter;
|
private int counter;
|
||||||
private String name;
|
private String name;
|
||||||
private int type;
|
private int type;
|
||||||
|
@ -60,6 +62,7 @@ public class Rotor
|
||||||
this.rrotor = backwardsRotor1;
|
this.rrotor = backwardsRotor1;
|
||||||
this.counter = setting;
|
this.counter = setting;
|
||||||
this.name="I";
|
this.name="I";
|
||||||
|
this.turnOver = 17; //"Royal"
|
||||||
this.type = 1;
|
this.type = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +72,7 @@ public class Rotor
|
||||||
this.rrotor = backwardsRotor2;
|
this.rrotor = backwardsRotor2;
|
||||||
this.counter = setting;
|
this.counter = setting;
|
||||||
this.name="II";
|
this.name="II";
|
||||||
|
this.turnOver = 5; //"Flags"
|
||||||
this.type = 2;
|
this.type = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +82,7 @@ public class Rotor
|
||||||
this.rrotor = backwardsRotor3;
|
this.rrotor = backwardsRotor3;
|
||||||
this.counter = setting;
|
this.counter = setting;
|
||||||
this.name="III";
|
this.name="III";
|
||||||
|
this.turnOver = 22; //"Wave"
|
||||||
this.type = 3;
|
this.type = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +92,7 @@ public class Rotor
|
||||||
this.rrotor = backwardsRotor4;
|
this.rrotor = backwardsRotor4;
|
||||||
this.counter = setting;
|
this.counter = setting;
|
||||||
this.name="IV";
|
this.name="IV";
|
||||||
|
this.turnOver = 10; //"Kings"
|
||||||
this.type = 4;
|
this.type = 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +102,7 @@ public class Rotor
|
||||||
this.rrotor = backwardsRotor5;
|
this.rrotor = backwardsRotor5;
|
||||||
this.counter = setting;
|
this.counter = setting;
|
||||||
this.name="V";
|
this.name="V";
|
||||||
|
this.turnOver = 0; //"Above"
|
||||||
this.type = 5;
|
this.type = 5;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -136,8 +143,8 @@ public class Rotor
|
||||||
*/
|
*/
|
||||||
public int encryptForward(int x)
|
public int encryptForward(int x)
|
||||||
{
|
{
|
||||||
return this.rotor[(26+x)%26];
|
return this.rotor[(26+x+ringsetting)%26];
|
||||||
}
|
} //TODO: Verify "+ringsetting"
|
||||||
|
|
||||||
/**encrypt in backward direction (coming from the reversing rotor)
|
/**encrypt in backward direction (coming from the reversing rotor)
|
||||||
* @param x incoming character
|
* @param x incoming character
|
||||||
|
@ -145,7 +152,7 @@ public class Rotor
|
||||||
*/
|
*/
|
||||||
public int encryptBackward(int x)
|
public int encryptBackward(int x)
|
||||||
{
|
{
|
||||||
if(this.rrotor ==null) return this.rotor[(26+x)%26];
|
if(this.rrotor == null) return this.rotor[(26+x+ringsetting)%26]; //TODO: Verify "+ringsetting"
|
||||||
else return this.rrotor[(26+x)%26];
|
else return this.rrotor[(26+x)%26];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +179,7 @@ public class Rotor
|
||||||
*/
|
*/
|
||||||
public boolean isAtTurnoverPosition()
|
public boolean isAtTurnoverPosition()
|
||||||
{
|
{
|
||||||
return this.getCounter() == this.getRingsetting(); //Todo: this ist still wrong.
|
return this.getCounter() == this.turnOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,7 +192,7 @@ public class Rotor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return ringsettings of the rotor (TODO: Find out, how ringsetting was implemented in original enigma. Wikipedia is not enough :/
|
* Return ringsettings of the rotor
|
||||||
* @return ringsetting
|
* @return ringsetting
|
||||||
*/
|
*/
|
||||||
public int getRingsetting()
|
public int getRingsetting()
|
||||||
|
|
Loading…
Reference in a new issue