mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-11-22 04:12:06 +01:00
Small changes
This commit is contained in:
parent
2bc5e62265
commit
8bab418e2b
21 changed files with 204 additions and 176 deletions
|
@ -3,6 +3,7 @@ v0.1.9-not-yet-released<
|
||||||
*Added option to share/receive configurations via QR-Code (ZXing Barcode Scanner)
|
*Added option to share/receive configurations via QR-Code (ZXing Barcode Scanner)
|
||||||
*Prevent user from setting incomplete reflector wiring
|
*Prevent user from setting incomplete reflector wiring
|
||||||
*Add option to generate configuration from passphrase
|
*Add option to generate configuration from passphrase
|
||||||
|
*TODO: Encode content of QR-Code completely in Base26(A..Z)
|
||||||
*TODO: Add Enigma Z (Probably wont happen due to lack of information :/)
|
*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: Add multi-Enigma (select any rotor/reflector etc. Probably wont happen too soon)
|
||||||
|
|
||||||
|
|
|
@ -372,8 +372,19 @@ public class MainActivity extends Activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set EnigmAndroid into a certain state as described in the QR-Code
|
||||||
|
* @param mem content of the QR-Code
|
||||||
|
*/
|
||||||
private void restoreStateFromCode(String mem)
|
private void restoreStateFromCode(String mem)
|
||||||
{
|
{
|
||||||
|
if(!mem.startsWith(APP_ID+"/"))
|
||||||
|
{
|
||||||
|
Toast.makeText(this, R.string.error_no_valid_qr, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mem = mem.substring((APP_ID+"/").length());
|
||||||
setPrefMachineType(Enigma.chooseEnigmaFromSave(mem));
|
setPrefMachineType(Enigma.chooseEnigmaFromSave(mem));
|
||||||
updateContentView();
|
updateContentView();
|
||||||
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
||||||
|
@ -381,7 +392,12 @@ public class MainActivity extends Activity
|
||||||
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
||||||
layoutContainer.syncStateFromEnigmaToLayout();
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set EnigmAndroid into a state calculated from the seed.
|
||||||
|
* @param seed seed
|
||||||
|
*/
|
||||||
public void createStateFromSeed(String seed)
|
public void createStateFromSeed(String seed)
|
||||||
{
|
{
|
||||||
setPrefMachineType(Enigma.chooseEnigmaFromSeed(seed));
|
setPrefMachineType(Enigma.chooseEnigmaFromSeed(seed));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.vanitasvitae.enigmandroid.enigma;
|
package de.vanitasvitae.enigmandroid.enigma;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ public class Enigma_D extends Enigma {
|
||||||
String reflectorConf = mem.substring(mem.lastIndexOf(":r")+2);
|
String reflectorConf = mem.substring(mem.lastIndexOf(":r")+2);
|
||||||
long s = Long.valueOf(mem.substring(0, mem.indexOf(":r")));
|
long s = Long.valueOf(mem.substring(0, mem.indexOf(":r")));
|
||||||
|
|
||||||
s = removeDigit(s, 12); //Remove machine type
|
s = removeDigit(s, 20); //Remove machine type
|
||||||
int rot1 = getValue(s, 26);
|
int rot1 = getValue(s, 26);
|
||||||
s = removeDigit(s, 26);
|
s = removeDigit(s, 26);
|
||||||
int ring1 = getValue(s, 26);
|
int ring1 = getValue(s, 26);
|
||||||
|
@ -186,7 +187,7 @@ public class Enigma_D extends Enigma {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String stateToString() {
|
public String stateToString() {
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = reflector.getRingSetting();
|
long s = reflector.getRingSetting();
|
||||||
s = addDigit(s, reflector.getRotation(), 26);
|
s = addDigit(s, reflector.getRotation(), 26);
|
||||||
s = addDigit(s, rotor3.getRingSetting(), 26);
|
s = addDigit(s, rotor3.getRingSetting(), 26);
|
||||||
|
@ -195,7 +196,7 @@ public class Enigma_D extends Enigma {
|
||||||
s = addDigit(s, rotor2.getRotation(), 26);
|
s = addDigit(s, rotor2.getRotation(), 26);
|
||||||
s = addDigit(s, rotor1.getRingSetting(), 26);
|
s = addDigit(s, rotor1.getRingSetting(), 26);
|
||||||
s = addDigit(s, rotor1.getRotation(), 26);
|
s = addDigit(s, rotor1.getRotation(), 26);
|
||||||
s = addDigit(s, 6, 12); //Machine #6
|
s = addDigit(s, 6, 20); //Machine #6
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
save = save + ":r" + Plugboard.configurationToString(getState().getConfigurationReflector());
|
save = save + ":r" + Plugboard.configurationToString(getState().getConfigurationReflector());
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.vanitasvitae.enigmandroid.enigma;
|
package de.vanitasvitae.enigmandroid.enigma;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the Enigma machine of type G31 (Abwehr)
|
* Implementation of the Enigma machine of type G31 (Abwehr)
|
||||||
* Copyright (C) 2015 Paul Schaub
|
* Copyright (C) 2015 Paul Schaub
|
||||||
|
@ -31,7 +33,7 @@ public class Enigma_G260 extends Enigma_G31
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = reflector.getRingSetting();
|
long s = reflector.getRingSetting();
|
||||||
s = addDigit(s, reflector.getRotation(), 26);
|
s = addDigit(s, reflector.getRotation(), 26);
|
||||||
s = addDigit(s, rotor3.getRingSetting(), 26);
|
s = addDigit(s, rotor3.getRingSetting(), 26);
|
||||||
|
@ -45,7 +47,7 @@ public class Enigma_G260 extends Enigma_G31
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
|
|
||||||
s = addDigit(s, 5, 12); //Machine #5
|
s = addDigit(s, 5, 20); //Machine #5
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package de.vanitasvitae.enigmandroid.enigma;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ public class Enigma_G31 extends Enigma
|
||||||
public void restoreState(String mem)
|
public void restoreState(String mem)
|
||||||
{
|
{
|
||||||
long s = Long.valueOf(mem);
|
long s = Long.valueOf(mem);
|
||||||
s = removeDigit(s, 12); //Remove machine type
|
s = removeDigit(s, 20); //Remove machine type
|
||||||
|
|
||||||
int r1 = getValue(s, 10);
|
int r1 = getValue(s, 10);
|
||||||
s = removeDigit(s, 10);
|
s = removeDigit(s, 10);
|
||||||
|
@ -201,7 +202,7 @@ public class Enigma_G31 extends Enigma
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = reflector.getRingSetting();
|
long s = reflector.getRingSetting();
|
||||||
s = addDigit(s, reflector.getRotation(), 26);
|
s = addDigit(s, reflector.getRotation(), 26);
|
||||||
s = addDigit(s, rotor3.getRingSetting(), 26);
|
s = addDigit(s, rotor3.getRingSetting(), 26);
|
||||||
|
@ -215,7 +216,7 @@ public class Enigma_G31 extends Enigma
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
|
|
||||||
s = addDigit(s, 3, 12); //Machine #3
|
s = addDigit(s, 3, 20); //Machine #3
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.vanitasvitae.enigmandroid.enigma;
|
package de.vanitasvitae.enigmandroid.enigma;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the Enigma machine of type G31 (Abwehr)
|
* Implementation of the Enigma machine of type G31 (Abwehr)
|
||||||
* Copyright (C) 2015 Paul Schaub
|
* Copyright (C) 2015 Paul Schaub
|
||||||
|
@ -30,7 +32,7 @@ public class Enigma_G312 extends Enigma_G31
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = reflector.getRingSetting();
|
long s = reflector.getRingSetting();
|
||||||
s = addDigit(s, reflector.getRotation(), 26);
|
s = addDigit(s, reflector.getRotation(), 26);
|
||||||
s = addDigit(s, rotor3.getRingSetting(), 26);
|
s = addDigit(s, rotor3.getRingSetting(), 26);
|
||||||
|
@ -44,7 +46,7 @@ public class Enigma_G312 extends Enigma_G31
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
|
|
||||||
s = addDigit(s, 4, 12); //Machine #4
|
s = addDigit(s, 4, 20); //Machine #4
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.vanitasvitae.enigmandroid.enigma;
|
package de.vanitasvitae.enigmandroid.enigma;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -156,7 +157,7 @@ public class Enigma_I extends Enigma
|
||||||
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
|
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
|
||||||
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
|
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
|
||||||
|
|
||||||
s = removeDigit(s, 12); //Remove machine type
|
s = removeDigit(s, 20); //Remove machine type
|
||||||
int r1 = getValue(s, 10);
|
int r1 = getValue(s, 10);
|
||||||
s = removeDigit(s, 10);
|
s = removeDigit(s, 10);
|
||||||
int r2 = getValue(s, 10);
|
int r2 = getValue(s, 10);
|
||||||
|
@ -188,7 +189,7 @@ public class Enigma_I extends Enigma
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String stateToString() {
|
public String stateToString() {
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = rotor3.getRingSetting();
|
long s = rotor3.getRingSetting();
|
||||||
s = addDigit(s, rotor3.getRotation(), 26);
|
s = addDigit(s, rotor3.getRotation(), 26);
|
||||||
s = addDigit(s, rotor2.getRingSetting(), 26);
|
s = addDigit(s, rotor2.getRingSetting(), 26);
|
||||||
|
@ -198,7 +199,7 @@ public class Enigma_I extends Enigma
|
||||||
s = addDigit(s, rotor3.getNumber(), 10);
|
s = addDigit(s, rotor3.getNumber(), 10);
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
s = addDigit(s, 0, 12); //Machine #0
|
s = addDigit(s, 0, 20); //Machine #0
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class Enigma_K extends Enigma
|
||||||
public void restoreState(String mem)
|
public void restoreState(String mem)
|
||||||
{
|
{
|
||||||
long s = Long.valueOf(mem);
|
long s = Long.valueOf(mem);
|
||||||
s = removeDigit(s,12); //Remove machine type
|
s = removeDigit(s,20); //Remove machine type
|
||||||
int r1 = getValue(s,10);
|
int r1 = getValue(s,10);
|
||||||
s = removeDigit(s,10);
|
s = removeDigit(s,10);
|
||||||
int r2 = getValue(s,10);
|
int r2 = getValue(s,10);
|
||||||
|
@ -201,7 +201,7 @@ public class Enigma_K extends Enigma
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long t = reflector.getRingSetting();
|
long t = reflector.getRingSetting();
|
||||||
t = addDigit(t, reflector.getRotation(), 26);
|
t = addDigit(t, reflector.getRotation(), 26);
|
||||||
t = addDigit(t, rotor3.getRingSetting(),26);
|
t = addDigit(t, rotor3.getRingSetting(),26);
|
||||||
|
@ -213,7 +213,7 @@ public class Enigma_K extends Enigma
|
||||||
t = addDigit(t, rotor3.getNumber(), 10);
|
t = addDigit(t, rotor3.getNumber(), 10);
|
||||||
t = addDigit(t, rotor2.getNumber(), 10);
|
t = addDigit(t, rotor2.getNumber(), 10);
|
||||||
t = addDigit(t, rotor1.getNumber(), 10);
|
t = addDigit(t, rotor1.getNumber(), 10);
|
||||||
t = addDigit(t, 7, 12); //Machine #7
|
t = addDigit(t, 7, 20); //Machine #7
|
||||||
|
|
||||||
save = save+t;
|
save = save+t;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.vanitasvitae.enigmandroid.enigma;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class Enigma_K_Swiss_Airforce extends Enigma_K
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long t = reflector.getRingSetting();
|
long t = reflector.getRingSetting();
|
||||||
t = addDigit(t, reflector.getRotation(), 26);
|
t = addDigit(t, reflector.getRotation(), 26);
|
||||||
t = addDigit(t, rotor3.getRingSetting(),26);
|
t = addDigit(t, rotor3.getRingSetting(),26);
|
||||||
|
@ -48,7 +49,7 @@ public class Enigma_K_Swiss_Airforce extends Enigma_K
|
||||||
t = addDigit(t, rotor3.getNumber(), 10);
|
t = addDigit(t, rotor3.getNumber(), 10);
|
||||||
t = addDigit(t, rotor2.getNumber(), 10);
|
t = addDigit(t, rotor2.getNumber(), 10);
|
||||||
t = addDigit(t, rotor1.getNumber(), 10);
|
t = addDigit(t, rotor1.getNumber(), 10);
|
||||||
t = addDigit(t, 9, 12); //Machine #9
|
t = addDigit(t, 9, 20); //Machine #9
|
||||||
|
|
||||||
save = save+t;
|
save = save+t;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.vanitasvitae.enigmandroid.enigma;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class Enigma_K_Swiss_Standard extends Enigma_K
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long t = reflector.getRingSetting();
|
long t = reflector.getRingSetting();
|
||||||
t = addDigit(t, reflector.getRotation(), 26);
|
t = addDigit(t, reflector.getRotation(), 26);
|
||||||
t = addDigit(t, rotor3.getRingSetting(),26);
|
t = addDigit(t, rotor3.getRingSetting(),26);
|
||||||
|
@ -48,7 +49,7 @@ public class Enigma_K_Swiss_Standard extends Enigma_K
|
||||||
t = addDigit(t, rotor3.getNumber(), 10);
|
t = addDigit(t, rotor3.getNumber(), 10);
|
||||||
t = addDigit(t, rotor2.getNumber(), 10);
|
t = addDigit(t, rotor2.getNumber(), 10);
|
||||||
t = addDigit(t, rotor1.getNumber(), 10);
|
t = addDigit(t, rotor1.getNumber(), 10);
|
||||||
t = addDigit(t, 8, 12); //Machine #8
|
t = addDigit(t, 8, 20); //Machine #8
|
||||||
|
|
||||||
save = save+t;
|
save = save+t;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.security.SecureRandom;
|
||||||
import java.sql.Ref;
|
import java.sql.Ref;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ public class Enigma_M3 extends Enigma_I
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String stateToString() {
|
public String stateToString() {
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = rotor3.getRingSetting();
|
long s = rotor3.getRingSetting();
|
||||||
s = addDigit(s, rotor3.getRotation(), 26);
|
s = addDigit(s, rotor3.getRotation(), 26);
|
||||||
s = addDigit(s, rotor2.getRingSetting(), 26);
|
s = addDigit(s, rotor2.getRingSetting(), 26);
|
||||||
|
@ -72,7 +73,7 @@ public class Enigma_M3 extends Enigma_I
|
||||||
s = addDigit(s, rotor3.getNumber(), 10);
|
s = addDigit(s, rotor3.getNumber(), 10);
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
s = addDigit(s, 1, 12); //Machine #1
|
s = addDigit(s, 1, 20); //Machine #1
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class Enigma_M4 extends Enigma
|
||||||
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
|
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
|
||||||
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
|
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
|
||||||
|
|
||||||
s = (s-(s%12))/12; //Remove machine type
|
s = removeDigit(s, 20); //Remove machine type
|
||||||
|
|
||||||
int r1 = getValue(s, 10);
|
int r1 = getValue(s, 10);
|
||||||
s = removeDigit(s, 10);
|
s = removeDigit(s, 10);
|
||||||
|
@ -248,7 +248,7 @@ public class Enigma_M4 extends Enigma
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String stateToString() {
|
public String stateToString() {
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long s = reflector.getRingSetting();
|
long s = reflector.getRingSetting();
|
||||||
s = addDigit(s, reflector.getRotation(), 26);
|
s = addDigit(s, reflector.getRotation(), 26);
|
||||||
s = addDigit(s, rotor4.getRingSetting(), 26);
|
s = addDigit(s, rotor4.getRingSetting(), 26);
|
||||||
|
@ -266,7 +266,7 @@ public class Enigma_M4 extends Enigma
|
||||||
s = addDigit(s, rotor2.getNumber(), 10);
|
s = addDigit(s, rotor2.getNumber(), 10);
|
||||||
s = addDigit(s, rotor1.getNumber(), 10);
|
s = addDigit(s, rotor1.getNumber(), 10);
|
||||||
|
|
||||||
s = addDigit(s, 2, 12);
|
s = addDigit(s, 2, 20);
|
||||||
|
|
||||||
save = save+s;
|
save = save+s;
|
||||||
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.vanitasvitae.enigmandroid.enigma;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -159,7 +160,7 @@ public class Enigma_R extends Enigma
|
||||||
public void restoreState(String mem)
|
public void restoreState(String mem)
|
||||||
{
|
{
|
||||||
long s = Long.valueOf(mem);
|
long s = Long.valueOf(mem);
|
||||||
s = removeDigit(s,12); //Remove machine type
|
s = removeDigit(s,20); //Remove machine type
|
||||||
int r1 = getValue(s,10);
|
int r1 = getValue(s,10);
|
||||||
s = removeDigit(s,10);
|
s = removeDigit(s,10);
|
||||||
int r2 = getValue(s,10);
|
int r2 = getValue(s,10);
|
||||||
|
@ -194,7 +195,7 @@ public class Enigma_R extends Enigma
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long t = reflector.getRingSetting();
|
long t = reflector.getRingSetting();
|
||||||
t = addDigit(t, reflector.getRotation(), 26);
|
t = addDigit(t, reflector.getRotation(), 26);
|
||||||
t = addDigit(t, rotor3.getRingSetting(),26);
|
t = addDigit(t, rotor3.getRingSetting(),26);
|
||||||
|
@ -206,7 +207,7 @@ public class Enigma_R extends Enigma
|
||||||
t = addDigit(t, rotor3.getNumber(), 10);
|
t = addDigit(t, rotor3.getNumber(), 10);
|
||||||
t = addDigit(t, rotor2.getNumber(), 10);
|
t = addDigit(t, rotor2.getNumber(), 10);
|
||||||
t = addDigit(t, rotor1.getNumber(), 10);
|
t = addDigit(t, rotor1.getNumber(), 10);
|
||||||
t = addDigit(t, 10, 12); //Machine #10
|
t = addDigit(t, 10, 20); //Machine #10
|
||||||
|
|
||||||
save = save+t;
|
save = save+t;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.util.Log;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ public class Enigma_T extends Enigma
|
||||||
public void restoreState(String mem)
|
public void restoreState(String mem)
|
||||||
{
|
{
|
||||||
long s = Long.valueOf(mem);
|
long s = Long.valueOf(mem);
|
||||||
s = removeDigit(s,12); //Remove machine type
|
s = removeDigit(s,20); //Remove machine type
|
||||||
int r1 = getValue(s,10);
|
int r1 = getValue(s,10);
|
||||||
s = removeDigit(s,10);
|
s = removeDigit(s,10);
|
||||||
int r2 = getValue(s,10);
|
int r2 = getValue(s,10);
|
||||||
|
@ -193,7 +194,7 @@ public class Enigma_T extends Enigma
|
||||||
@Override
|
@Override
|
||||||
public String stateToString()
|
public String stateToString()
|
||||||
{
|
{
|
||||||
String save = "";
|
String save = MainActivity.APP_ID+"/";
|
||||||
long t = reflector.getRingSetting();
|
long t = reflector.getRingSetting();
|
||||||
t = addDigit(t, reflector.getRotation(), 26);
|
t = addDigit(t, reflector.getRotation(), 26);
|
||||||
t = addDigit(t, rotor3.getRingSetting(),26);
|
t = addDigit(t, rotor3.getRingSetting(),26);
|
||||||
|
@ -205,7 +206,7 @@ public class Enigma_T extends Enigma
|
||||||
t = addDigit(t, rotor3.getNumber(), 10);
|
t = addDigit(t, rotor3.getNumber(), 10);
|
||||||
t = addDigit(t, rotor2.getNumber(), 10);
|
t = addDigit(t, rotor2.getNumber(), 10);
|
||||||
t = addDigit(t, rotor1.getNumber(), 10);
|
t = addDigit(t, rotor1.getNumber(), 10);
|
||||||
t = addDigit(t, 11, 12); //Machine #11
|
t = addDigit(t, 11, 20); //Machine #11
|
||||||
|
|
||||||
save = save+t;
|
save = save+t;
|
||||||
return save;
|
return save;
|
||||||
|
|
|
@ -168,4 +168,17 @@ public class Plugboard
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long configurationToLong(int[] a)
|
||||||
|
{
|
||||||
|
String s = configurationToString(a);
|
||||||
|
long l = 0;
|
||||||
|
for(char c : s.toCharArray())
|
||||||
|
{
|
||||||
|
int i = (int) (c);
|
||||||
|
i-=65;
|
||||||
|
Enigma.addDigit(l,i,26);
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,126 +0,0 @@
|
||||||
package de.vanitasvitae.enigmandroid.enigma;
|
|
||||||
|
|
||||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by vanitas on 18.09.15.
|
|
||||||
*/
|
|
||||||
public class SeedInterpreter
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
12 machineType
|
|
||||||
1-8 rotor1
|
|
||||||
1-8 rotor2
|
|
||||||
1-8 rotor3
|
|
||||||
2 rotor4
|
|
||||||
1-3 ukw
|
|
||||||
26 pos1
|
|
||||||
26 pos2
|
|
||||||
26 pos3
|
|
||||||
26 pos4/posukw
|
|
||||||
--plugboard
|
|
||||||
#plugs 13
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
public double prepareSeed(long input)
|
|
||||||
{
|
|
||||||
double maxIn = Long.MAX_VALUE;
|
|
||||||
double maxOut = 100000; //TODO: Temporär!
|
|
||||||
|
|
||||||
return (input / maxIn) * maxOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle seedToState(long seed)
|
|
||||||
{
|
|
||||||
long s = seed/12;
|
|
||||||
switch ((int) seed % 12)
|
|
||||||
{
|
|
||||||
case 0: return prepState_I(s);
|
|
||||||
case 1: return prepState_M3(s);
|
|
||||||
case 2: return prepState_M4(s);
|
|
||||||
case 3: return prepState_G31(s);
|
|
||||||
case 4: return prepState_G312(s);
|
|
||||||
case 5: return prepState_G260(s);
|
|
||||||
case 6: return prepState_D(s);
|
|
||||||
case 7: return prepState_K(s);
|
|
||||||
case 8: return prepState_KS(s);
|
|
||||||
case 9: return prepState_KSA(s);
|
|
||||||
case 10: return prepState_R(s);
|
|
||||||
default: return prepState_T(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_I(long seed)
|
|
||||||
{
|
|
||||||
EnigmaStateBundle state = new EnigmaStateBundle();
|
|
||||||
state.setMachineType("I");
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_M3(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_M4(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_G31(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_G312(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_G260(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_D(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_K(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_KS(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_KSA(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_R(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EnigmaStateBundle prepState_T(long seed)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] getPermutation(long seed)
|
|
||||||
{
|
|
||||||
int[] per = Reflector.ReflectorEnigma_D_KD_G31.defaultWiring_D_KD_G31;
|
|
||||||
long maxPermutations = Long.valueOf("532985208200576");
|
|
||||||
//long result =
|
|
||||||
return per;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,21 +5,17 @@ import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import de.vanitasvitae.enigmandroid.MainActivity;
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.R;
|
import de.vanitasvitae.enigmandroid.R;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for the dialog that is used to get settings for the rings
|
* Builder for the dialog that is used to obtain a passphrase to generate
|
||||||
|
* a enigma configuration from it.
|
||||||
* Copyright (C) 2015 Paul Schaub
|
* Copyright (C) 2015 Paul Schaub
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -51,22 +47,27 @@ public class PassphraseDialogBuilder
|
||||||
passphrase.addTextChangedListener(new TextWatcher() {
|
passphrase.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
//Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
//Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
|
//Count input text and enable positive button if length > 0.
|
||||||
|
//Disable else
|
||||||
if(s.length() > 0) positive.setEnabled(true);
|
if(s.length() > 0) positive.setEnabled(true);
|
||||||
else positive.setEnabled(false);
|
else positive.setEnabled(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create and show the dialog
|
||||||
|
*/
|
||||||
public void showDialog()
|
public void showDialog()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package de.vanitasvitae.enigmandroid.layout;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
@ -18,7 +17,8 @@ import de.vanitasvitae.enigmandroid.R;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for the dialog that is used to get settings for the rings
|
* Builder for the dialog that is used to plug the plugboard/wire the
|
||||||
|
* rewirable reflector.
|
||||||
* Copyright (C) 2015 Paul Schaub
|
* Copyright (C) 2015 Paul Schaub
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -50,6 +50,10 @@ public class PluggableDialogBuilder
|
||||||
|
|
||||||
protected int previouslyPressedButton = -1;
|
protected int previouslyPressedButton = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that prepares layout and buttons.
|
||||||
|
* @param state EnigmaStateBundle from which dialog gets restored and which gets manipulated
|
||||||
|
*/
|
||||||
public PluggableDialogBuilder(EnigmaStateBundle state)
|
public PluggableDialogBuilder(EnigmaStateBundle state)
|
||||||
{
|
{
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
@ -58,6 +62,9 @@ public class PluggableDialogBuilder
|
||||||
setButtonListeners();
|
setButtonListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show dialog for the plugboard
|
||||||
|
*/
|
||||||
public void showDialogPlugboard()
|
public void showDialogPlugboard()
|
||||||
{
|
{
|
||||||
allowIncompleteConnections = true;
|
allowIncompleteConnections = true;
|
||||||
|
@ -93,6 +100,10 @@ public class PluggableDialogBuilder
|
||||||
d.getWindow().setAttributes(lp);
|
d.getWindow().setAttributes(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the dialog for the reflector. This can only be positively closed when all
|
||||||
|
* connections are made.
|
||||||
|
*/
|
||||||
public void showDialogReflector()
|
public void showDialogReflector()
|
||||||
{
|
{
|
||||||
allowIncompleteConnections = false;
|
allowIncompleteConnections = false;
|
||||||
|
@ -132,6 +143,10 @@ public class PluggableDialogBuilder
|
||||||
}
|
}
|
||||||
d.getWindow().setAttributes(lp);
|
d.getWindow().setAttributes(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize array of buttons, initialize background-color hashset.
|
||||||
|
*/
|
||||||
public void initializeLayout()
|
public void initializeLayout()
|
||||||
{
|
{
|
||||||
buttons = new ArrayList<>();
|
buttons = new ArrayList<>();
|
||||||
|
@ -178,9 +193,11 @@ public class PluggableDialogBuilder
|
||||||
colors.add(R.drawable.button_pink);
|
colors.add(R.drawable.button_pink);
|
||||||
colors.add(R.drawable.button_elder);
|
colors.add(R.drawable.button_elder);
|
||||||
colors.add(R.drawable.button_black);
|
colors.add(R.drawable.button_black);
|
||||||
Log.d("Dialogtest", ""+R.drawable.button_red);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set listeners for all buttons
|
||||||
|
*/
|
||||||
public void setButtonListeners()
|
public void setButtonListeners()
|
||||||
{
|
{
|
||||||
for(int i=0; i<26; i++)
|
for(int i=0; i<26; i++)
|
||||||
|
@ -196,6 +213,11 @@ public class PluggableDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check, whether all connections are done. If so, return true.
|
||||||
|
* return false otherwise
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
protected boolean allConnectionsDone()
|
protected boolean allConnectionsDone()
|
||||||
{
|
{
|
||||||
for(int i=0; i<buttons.size(); i++)
|
for(int i=0; i<buttons.size(); i++)
|
||||||
|
@ -206,16 +228,26 @@ public class PluggableDialogBuilder
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* restore the connections according to the plugboard
|
||||||
|
*/
|
||||||
protected void restoreConfigurationPlugboard()
|
protected void restoreConfigurationPlugboard()
|
||||||
{
|
{
|
||||||
restoreConfiguration(state.getConfigurationPlugboard());
|
restoreConfiguration(state.getConfigurationPlugboard());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* restore the connections according to the reflector
|
||||||
|
*/
|
||||||
protected void restoreConfigurationReflector()
|
protected void restoreConfigurationReflector()
|
||||||
{
|
{
|
||||||
restoreConfiguration(state.getConfigurationReflector());
|
restoreConfiguration(state.getConfigurationReflector());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect all the buttons according to c.
|
||||||
|
* @param c array of connections
|
||||||
|
*/
|
||||||
protected void restoreConfiguration(int[] c)
|
protected void restoreConfiguration(int[] c)
|
||||||
{
|
{
|
||||||
for(int i=0; i<26; i++)
|
for(int i=0; i<26; i++)
|
||||||
|
@ -224,6 +256,14 @@ public class PluggableDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect button1 and button2. If two buttons got pressed afterwards and they are not the same
|
||||||
|
* they get connected. If one or both of them was connected beforehand, these connections get
|
||||||
|
* resolved. If both events come from the same button, the buttons connections (if any) get
|
||||||
|
* resolved.
|
||||||
|
* @param button1 first and
|
||||||
|
* @param button2 second button
|
||||||
|
*/
|
||||||
public void setPlug(int button1, int button2)
|
public void setPlug(int button1, int button2)
|
||||||
{
|
{
|
||||||
if(button1 == button2)
|
if(button1 == button2)
|
||||||
|
@ -258,6 +298,10 @@ public class PluggableDialogBuilder
|
||||||
updatePositiveButton();
|
updatePositiveButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update state of positive button. Check, if all connections are done and if so, enable positive
|
||||||
|
* button. Otherwise disable it.
|
||||||
|
*/
|
||||||
protected void updatePositiveButton()
|
protected void updatePositiveButton()
|
||||||
{
|
{
|
||||||
if(!allowIncompleteConnections && positive != null)
|
if(!allowIncompleteConnections && positive != null)
|
||||||
|
@ -267,6 +311,11 @@ public class PluggableDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set buttons to not connected. That includes changing background to grey, set connection to
|
||||||
|
* itself.
|
||||||
|
* @param b
|
||||||
|
*/
|
||||||
private void setButtonFree(int b)
|
private void setButtonFree(int b)
|
||||||
{
|
{
|
||||||
ButtonWrapper button = buttons.get(b);
|
ButtonWrapper button = buttons.get(b);
|
||||||
|
@ -277,6 +326,10 @@ public class PluggableDialogBuilder
|
||||||
button.setConnectedButton(b);
|
button.setConnectedButton(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle button pressed events.
|
||||||
|
* @param button button that got pressed
|
||||||
|
*/
|
||||||
public void buttonPressed(int button)
|
public void buttonPressed(int button)
|
||||||
{
|
{
|
||||||
if(previouslyPressedButton != -1)
|
if(previouslyPressedButton != -1)
|
||||||
|
@ -291,12 +344,22 @@ public class PluggableDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class for Buttons, that also stores the index of both, the connected button, as well
|
||||||
|
* as the button itself and resourceID of used material.
|
||||||
|
*/
|
||||||
private static class ButtonWrapper
|
private static class ButtonWrapper
|
||||||
{
|
{
|
||||||
private Button button;
|
private Button button;
|
||||||
private int connectedButton;
|
private int connectedButton;
|
||||||
private int resourceID;
|
private int resourceID;
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create ButtonWrapper
|
||||||
|
* @param button underlying Button
|
||||||
|
* @param index index of the button in the buttons array
|
||||||
|
*/
|
||||||
public ButtonWrapper(Button button, int index)
|
public ButtonWrapper(Button button, int index)
|
||||||
{
|
{
|
||||||
this.button = button;
|
this.button = button;
|
||||||
|
@ -304,33 +367,56 @@ public class PluggableDialogBuilder
|
||||||
this.connectedButton = index;
|
this.connectedButton = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the index of the connected button and update buttons text
|
||||||
|
* @param other index
|
||||||
|
*/
|
||||||
public void setConnectedButton(int other)
|
public void setConnectedButton(int other)
|
||||||
{
|
{
|
||||||
this.connectedButton = other;
|
this.connectedButton = other;
|
||||||
this.getButton().setText((char) (index + 65) + ":" + (char) (connectedButton + 65));
|
this.getButton().setText((char) (index + 65) + ":" + (char) (connectedButton + 65));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return index of the connected button
|
||||||
|
* @return index of connected button
|
||||||
|
*/
|
||||||
public int getConnectedButton()
|
public int getConnectedButton()
|
||||||
{
|
{
|
||||||
return this.connectedButton;
|
return this.connectedButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate, that this button is waiting for another button to connect to.
|
||||||
|
*/
|
||||||
public void setWaiting()
|
public void setWaiting()
|
||||||
{
|
{
|
||||||
this.getButton().setText((char) (index + 65) + ": ");
|
this.getButton().setText((char) (index + 65) + ": ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set buttons background and store value in resourceID
|
||||||
|
* @param r resourceID of background material
|
||||||
|
*/
|
||||||
public void setResourceID(int r)
|
public void setResourceID(int r)
|
||||||
{
|
{
|
||||||
button.setBackgroundResource(r);
|
button.setBackgroundResource(r);
|
||||||
this.resourceID = r;
|
this.resourceID = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get resourceID of buttons background as store in resourceID
|
||||||
|
* @return resourceID
|
||||||
|
*/
|
||||||
public int getResourceID()
|
public int getResourceID()
|
||||||
{
|
{
|
||||||
return this.resourceID;
|
return this.resourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return stored button object
|
||||||
|
* @return button
|
||||||
|
*/
|
||||||
public Button getButton()
|
public Button getButton()
|
||||||
{
|
{
|
||||||
return button;
|
return button;
|
||||||
|
|
|
@ -46,6 +46,10 @@ public abstract class RingSettingsDialogBuilder
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a ArrayAdapter working over an array of numbers 1 to 26.
|
||||||
|
* @return ArrayAdapter
|
||||||
|
*/
|
||||||
public static ArrayAdapter createAdapter1_26()
|
public static ArrayAdapter createAdapter1_26()
|
||||||
{
|
{
|
||||||
Integer[] ringArray = new Integer[26];
|
Integer[] ringArray = new Integer[26];
|
||||||
|
@ -54,7 +58,9 @@ public abstract class RingSettingsDialogBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DialogBuilder for 3 Spinners and ringSettingRotor1-3
|
||||||
|
*/
|
||||||
public static class RingSettingsDialogBuilderRotRotRot extends RingSettingsDialogBuilder
|
public static class RingSettingsDialogBuilderRotRotRot extends RingSettingsDialogBuilder
|
||||||
{
|
{
|
||||||
public void createRingSettingsDialog(final EnigmaStateBundle state)
|
public void createRingSettingsDialog(final EnigmaStateBundle state)
|
||||||
|
@ -161,6 +167,9 @@ public abstract class RingSettingsDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DialogBuilder for 4 Spinners and ringSettingRotor1-3, ringSettingReflector
|
||||||
|
*/
|
||||||
public static class RingSettingsDialogBuilderRotRotRotRef extends RingSettingsDialogBuilder
|
public static class RingSettingsDialogBuilderRotRotRotRef extends RingSettingsDialogBuilder
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -286,6 +295,9 @@ public abstract class RingSettingsDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DialogBuilder for 4 Spinners and ringSettingRotor1-4
|
||||||
|
*/
|
||||||
public static class RingSettingsDialogBuilderRotRotRotRot extends RingSettingsDialogBuilderRotRotRotRef
|
public static class RingSettingsDialogBuilderRotRotRotRot extends RingSettingsDialogBuilderRotRotRotRef
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -346,6 +358,9 @@ public abstract class RingSettingsDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class that defines how Spinners correspond to the EnigmaStateBundle
|
||||||
|
*/
|
||||||
public static abstract class Actions
|
public static abstract class Actions
|
||||||
{
|
{
|
||||||
protected EnigmaStateBundle stateBundle;
|
protected EnigmaStateBundle stateBundle;
|
||||||
|
@ -355,6 +370,10 @@ public abstract class RingSettingsDialogBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class that defines, how the 3 Spinners correspond to 3 values in the
|
||||||
|
* EnigmaStateBundle
|
||||||
|
*/
|
||||||
public static abstract class Actions3 extends Actions
|
public static abstract class Actions3 extends Actions
|
||||||
{
|
{
|
||||||
public Actions3(EnigmaStateBundle bundle)
|
public Actions3(EnigmaStateBundle bundle)
|
||||||
|
@ -369,6 +388,10 @@ public abstract class RingSettingsDialogBuilder
|
||||||
protected abstract int getThirdValueFromBundle();
|
protected abstract int getThirdValueFromBundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension of Actions3 which forces implementing classes to implement methods for the fourth
|
||||||
|
* Spinner.
|
||||||
|
*/
|
||||||
public static abstract class Actions4 extends Actions3
|
public static abstract class Actions4 extends Actions3
|
||||||
{
|
{
|
||||||
public Actions4(EnigmaStateBundle bundle)
|
public Actions4(EnigmaStateBundle bundle)
|
||||||
|
|
|
@ -27,12 +27,13 @@
|
||||||
<string name="hint_reflector_position">Position\nUmkehr-\nWalze</string>
|
<string name="hint_reflector_position">Position\nUmkehr-\nWalze</string>
|
||||||
<string name="hint_thin_rotor_position">Position\nWalze 4</string>
|
<string name="hint_thin_rotor_position">Position\nWalze 4</string>
|
||||||
<string name="hint_enigma_reflector_wiring">Verkabelung Umkehrwalze</string>
|
<string name="hint_enigma_reflector_wiring">Verkabelung Umkehrwalze</string>
|
||||||
<string name="hint_passphrase">Passphrase eingeben</string>
|
<string name="hint_passphrase">Schlüsselwort eingeben</string>
|
||||||
<string name="button_crypt">Ver-/Entschlüsseln</string>
|
<string name="button_crypt">Ver-/Entschlüsseln</string>
|
||||||
<string name="error_parsing_plugs">Fehler: Fehlerhafte Steckerbrettkonfiguration.</string>
|
<string name="error_parsing_plugs">Fehler: Fehlerhafte Steckerbrettkonfiguration.</string>
|
||||||
<string name="error_unable_to_plug_a_b">Kann Stecker nicht setzen: </string>
|
<string name="error_unable_to_plug_a_b">Kann Stecker nicht setzen: </string>
|
||||||
<string name="error_plug_already_in_use">Fehler: Einer oder mehrere dieser Stecker sind bereits in Benutzung: </string>
|
<string name="error_plug_already_in_use">Fehler: Einer oder mehrere dieser Stecker sind bereits in Benutzung: </string>
|
||||||
<string name="error_no_text_to_send">Nachricht ist leer.</string>
|
<string name="error_no_text_to_send">Nachricht ist leer.</string>
|
||||||
|
<string name="error_no_valid_qr">Fehler: Kein korrekter EnigmAndroid QR-Code!</string>
|
||||||
<string name="title_ringsetting">Ringstellungen</string>
|
<string name="title_ringsetting">Ringstellungen</string>
|
||||||
<string name="title_plugboard_dialog">Steckbrett-\nVerbindungen</string>
|
<string name="title_plugboard_dialog">Steckbrett-\nVerbindungen</string>
|
||||||
<string name="title_reflector_dialog">Verkabelung Umkehrwalze</string>
|
<string name="title_reflector_dialog">Verkabelung Umkehrwalze</string>
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
<string name="error_unable_to_plug_a_b">Unable to plug </string>
|
<string name="error_unable_to_plug_a_b">Unable to plug </string>
|
||||||
<string name="error_plug_already_in_use">Error: One or more of these plugs are already in use:</string>
|
<string name="error_plug_already_in_use">Error: One or more of these plugs are already in use:</string>
|
||||||
<string name="error_no_text_to_send">Can\'t send empty text.</string>
|
<string name="error_no_text_to_send">Can\'t send empty text.</string>
|
||||||
|
<string name="error_no_valid_qr">Error: Not a valid EnigmAndroid QR-Code!</string>
|
||||||
<string name="title_ringsetting">Ring-Settings</string>
|
<string name="title_ringsetting">Ring-Settings</string>
|
||||||
<string name="title_plugboard_dialog">Plugboard Settings</string>
|
<string name="title_plugboard_dialog">Plugboard Settings</string>
|
||||||
<string name="title_reflector_dialog">Reflector Wiring</string>
|
<string name="title_reflector_dialog">Reflector Wiring</string>
|
||||||
|
|
Loading…
Reference in a new issue