mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-11-24 21:32:06 +01:00
Added Button to set selected enigma to random configuration
This commit is contained in:
parent
82e21e48ec
commit
95f449d743
33 changed files with 401 additions and 22 deletions
|
@ -12,10 +12,10 @@ v0.1.8-not-yet-released<
|
|||
*Added different colors to the plugboard-/pluggable reflector dialog. This helps to differentiate connections.
|
||||
*Reworked InputPreparer using decorator pattern and added options to customize input preparation
|
||||
*Reworked Reflector-/Rotor creation/management
|
||||
*Added Button to set the Enigma into a random configuration
|
||||
*TODO: Add Enigma Z (Probably wont happen due to lack of information :/)
|
||||
*TODO: Add multi-Enigma (select any rotor/reflector etc. Probably wont happen too soon)
|
||||
*TODO: Button to set the Enigma into a random configuration
|
||||
*TODO: Enigma configuration from seed (text or qr code)
|
||||
*TODO: Enigma configuration from/to seed (text or qr code)
|
||||
|
||||
v0.1.7-15.09.2015<
|
||||
*Added Enigma K
|
||||
|
|
|
@ -287,6 +287,14 @@ public class MainActivity extends Activity
|
|||
Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
else if (id == R.id.action_random_configuration)
|
||||
{
|
||||
layoutContainer.getEnigma().randomState();
|
||||
layoutContainer.setLayoutState(layoutContainer.getEnigma().getState());
|
||||
Toast.makeText(getApplicationContext(), R.string.message_random,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
else if (id == R.id.action_choose_ringstellung)
|
||||
{
|
||||
layoutContainer.showRingSettingsDialog();
|
||||
|
|
|
@ -65,6 +65,13 @@ public abstract class Enigma
|
|||
*/
|
||||
public abstract void nextState();
|
||||
|
||||
/**
|
||||
* Set the enigma to a random state.
|
||||
* Don not choose a rotor twice, set random rotations, ringSettings, ukw and possibly
|
||||
* plugboard / rewirable ukw configurations.
|
||||
*/
|
||||
public abstract void randomState();
|
||||
|
||||
/**
|
||||
* Substitute char k by sending the signal through the enigma.
|
||||
* The signal passes the plugboard, the rotors and returns back after going through the
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
/**
|
||||
* Concrete implementation of an enigma machine of type I
|
||||
* Concrete implementation of an enigma machine of type D
|
||||
* This machine has a rewirable UKW, non changeable rotors.
|
||||
* Copyright (C) 2015 Paul Schaub
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -61,6 +65,27 @@ public class Enigma_D extends Enigma {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(70, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(71, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(72, rot3, ring3);
|
||||
this.reflector = (Reflector.ReflectorEnigma_D_KD_G31) Reflector.createReflector(70);
|
||||
this.reflector.setRotation(rotRef);
|
||||
this.reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -38,4 +41,31 @@ public class Enigma_G260 extends Enigma_G31
|
|||
this.rotor3 = Rotor.createRotor(62, 0, 0);
|
||||
this.reflector = Reflector.createReflector(60);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(60 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(60 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(60 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(60);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package de.vanitasvitae.enigmandroid.enigma;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -67,6 +70,33 @@ public class Enigma_G31 extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(40 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(40 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(40 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(40);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.sql.Ref;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
@ -40,4 +42,31 @@ public class Enigma_G312 extends Enigma_G31
|
|||
this.rotor3 = Rotor.createRotor(52, 0, 0);
|
||||
this.reflector = Reflector.createReflector(50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(50 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(50 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(50 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(50);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -63,6 +66,30 @@ public class Enigma_I extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(5);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(5);
|
||||
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(5);
|
||||
int ref = rand.nextInt(3);
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(10 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(10 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(10 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(10 + ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -61,6 +64,33 @@ public class Enigma_K extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(80 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(80 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(80 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(80);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -61,6 +64,33 @@ public class Enigma_K_Swiss_Airforce extends Enigma_K
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(100 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(100 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(100 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(100);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -61,6 +64,33 @@ public class Enigma_K_Swiss_Standard extends Enigma_K
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(90 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(90 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(90 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(90);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.sql.Ref;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -37,4 +41,28 @@ public class Enigma_M3 extends Enigma_I
|
|||
this.rotor3 = Rotor.createRotor(22, 0, 0);
|
||||
this.reflector = Reflector.createReflector(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(8);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(8);
|
||||
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(8);
|
||||
int ref = rand.nextInt(2);
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(20 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(20 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(20 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(20 + ref);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -75,6 +78,40 @@ public class Enigma_M4 extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
int rotor4;
|
||||
int ref;
|
||||
rotor1 = rand.nextInt(8);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(8);
|
||||
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(8);
|
||||
rotor4 = rand.nextInt(2);
|
||||
ref = rand.nextInt(2);
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rot4 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ring4 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(30 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(30 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(30 + rotor3, rot3, ring3);
|
||||
this.rotor4 = Rotor.createRotor(38 + rotor4, rot4, ring4);
|
||||
this.reflector = Reflector.createReflector(30 + ref);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Substitute char k by sending the signal through the enigma.
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -61,6 +64,33 @@ public class Enigma_R extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(3);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
|
||||
rotor3 = 3 - rotor1 - rotor2;
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(110 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(110 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(110 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(110);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -2,6 +2,9 @@ package de.vanitasvitae.enigmandroid.enigma;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -62,6 +65,33 @@ public class Enigma_T extends Enigma
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomState()
|
||||
{
|
||||
Random rand = new SecureRandom();
|
||||
|
||||
int rotor1, rotor2=-1, rotor3=-1;
|
||||
rotor1 = rand.nextInt(8);
|
||||
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(8);
|
||||
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(8);
|
||||
|
||||
int rot1 = rand.nextInt(26);
|
||||
int rot2 = rand.nextInt(26);
|
||||
int rot3 = rand.nextInt(26);
|
||||
int rotRef = rand.nextInt(26);
|
||||
int ring1 = rand.nextInt(26);
|
||||
int ring2 = rand.nextInt(26);
|
||||
int ring3 = rand.nextInt(26);
|
||||
int ringRef = rand.nextInt(26);
|
||||
|
||||
this.rotor1 = Rotor.createRotor(120 + rotor1, rot1, ring1);
|
||||
this.rotor2 = Rotor.createRotor(120 + rotor2, rot2, ring2);
|
||||
this.rotor3 = Rotor.createRotor(120 + rotor3, rot3, ring3);
|
||||
this.reflector = Reflector.createReflector(120);
|
||||
reflector.setRotation(rotRef);
|
||||
reflector.setRingSetting(ringRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class LayoutContainer
|
|||
public abstract Enigma getEnigma();
|
||||
protected abstract void initializeLayout();
|
||||
public abstract void resetLayout();
|
||||
protected abstract void setLayoutState(EnigmaStateBundle state);
|
||||
public abstract void setLayoutState(EnigmaStateBundle state);
|
||||
protected abstract void refreshState();
|
||||
public abstract void showRingSettingsDialog();
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public class LayoutContainer_D extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1PositionView.setSelection(state.getRotationRotor1());
|
||||
|
|
|
@ -113,7 +113,7 @@ public class LayoutContainer_G260 extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - offsetRot);
|
||||
|
|
|
@ -113,7 +113,7 @@ public class LayoutContainer_G31 extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - offsetRot);
|
||||
|
|
|
@ -113,7 +113,7 @@ public class LayoutContainer_G312 extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - offsetRot);
|
||||
|
|
|
@ -114,7 +114,7 @@ public class LayoutContainer_I extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 10);
|
||||
|
|
|
@ -112,7 +112,7 @@ public class LayoutContainer_K extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 80);
|
||||
|
|
|
@ -112,7 +112,7 @@ public class LayoutContainer_K_Swiss extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 90);
|
||||
|
|
|
@ -112,7 +112,7 @@ public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 100);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class LayoutContainer_M3 extends LayoutContainer_I
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 20);
|
||||
|
|
|
@ -139,7 +139,7 @@ public class LayoutContainer_M4 extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state) {
|
||||
public void setLayoutState(EnigmaStateBundle state) {
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 30);
|
||||
this.rotor2View.setSelection(state.getTypeRotor2() - 30);
|
||||
|
|
|
@ -111,7 +111,7 @@ public class LayoutContainer_R extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 110);
|
||||
|
|
|
@ -111,7 +111,7 @@ public class LayoutContainer_T extends LayoutContainer
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
public void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1() - 120);
|
||||
|
|
|
@ -3,14 +3,18 @@
|
|||
tools:context=".MainActivity" >
|
||||
|
||||
<item android:id="@+id/action_reset"
|
||||
android:orderInCategory="96"
|
||||
android:orderInCategory="95"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/action_reset" />
|
||||
<item android:id="@+id/action_send"
|
||||
android:orderInCategory="97"
|
||||
android:orderInCategory="96"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/action_send"
|
||||
android:icon="@drawable/ic_send_white_48dp"/>
|
||||
<item android:id="@+id/action_random_configuration"
|
||||
android:orderInCategory="97"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/action_random" />
|
||||
<item android:id="@+id/action_choose_ringstellung"
|
||||
android:title="@string/action_choose_ringsettings"
|
||||
android:orderInCategory="98"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<string name="app_name">EnigmAndroid</string>
|
||||
<string name="action_version">Version</string>
|
||||
<string name="action_reset">Zurücksetzen</string>
|
||||
<string name="action_random">Zufällige Konfiguration</string>
|
||||
<string name="action_settings">Einstellungen</string>
|
||||
<string name="action_choose_ringsettings">Ringstellung</string>
|
||||
<string name="action_send">Senden</string>
|
||||
|
@ -39,5 +40,6 @@
|
|||
<string name="dialog_plugboard_set">Steckbrett gesteckert.</string>
|
||||
<string name="dialog_abort">Keine Änderungen</string>
|
||||
<string name="message_reset">Enigma zurückgesetzt</string>
|
||||
<string name="message_random">Enigma auf zufällige Konfiguration gesetzt</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
<item>G260 (Abwehr)</item>
|
||||
<item>D (Kommerziell)</item>
|
||||
<item>K</item>
|
||||
<item>K (Schweiz)</item>
|
||||
<item>K (Schweiz, Luftwaffe)</item>
|
||||
<item>Swiss-K (Schweiz)</item>
|
||||
<item>Swiss-K (Schweiz, Luftwaffe)</item>
|
||||
<item>R (\"Rocket\", Reichsbahn)</item>
|
||||
<item>T (\"Tirpitz\", Japan)</item>
|
||||
</string-array>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<string name="app_name">EnigmAndroid</string>
|
||||
<string name="action_version">Version</string>
|
||||
<string name="action_reset">Reset</string>
|
||||
<string name="action_random">Random configuration</string>
|
||||
<string name="action_choose_ringsettings">Ring-Settings</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_send">Send</string>
|
||||
|
@ -40,6 +41,7 @@
|
|||
<string name="dialog_plugboard_set">Plugged Plugboard.</string>
|
||||
<string name="dialog_abort">No changes</string>
|
||||
<string name="message_reset">Enigma reset</string>
|
||||
<string name="message_random">Enigma set to random configuration</string>
|
||||
|
||||
<string-array translatable="false" name="rotors_1_3">
|
||||
<item>I</item>
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
<item>G260 (Defense)</item>
|
||||
<item>D (Commercial)</item>
|
||||
<item>K</item>
|
||||
<item>K (Swiss)</item>
|
||||
<item>K (Swiss, Airforce)</item>
|
||||
<item>Swiss-K</item>
|
||||
<item>Swiss-K (Airforce)</item>
|
||||
<item>R (\"Rocket\", Railway)</item>
|
||||
<item>T (\"Tirpitz\", Japan)</item>
|
||||
</string-array>
|
||||
|
|
Loading…
Reference in a new issue