diff --git a/app/app.iml b/app/app.iml
index 032b5df..119070b 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -59,7 +59,7 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index 9822add..d61206c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 20
+ compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "de.vanitasvitae.enigmandroid"
minSdkVersion 15
- targetSdkVersion 20
- versionCode 5
- versionName "17.02.2015-beta"
+ targetSdkVersion 21
+ versionCode 6
+ versionName "0.1.1-18.02.2015-beta"
}
buildTypes {
release {
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java
index effdec9..5459367 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java
@@ -3,149 +3,153 @@ package de.vanitasvitae.enigmandroid;
/**
* Enigma-machine
- * @author vanitasvitae
*
+ * @author vanitasvitae
*/
-public class Enigma
+public class Enigma
{
- private Plugboard plugboard;
+ private Plugboard plugboard;
//Slots for the rotors
- private Rotor r1;
- private Rotor r2;
- private Rotor r3;
+ private Rotor r1;
+ private Rotor r2;
+ private Rotor r3;
//Slot for the reflector
- private Rotor reflector;
+ private Rotor reflector;
private boolean anomaly;
- //Standard configuration (rotors 1-3, reflector B, all three rotors set to position 1)
- private static final int[] STANDARD_CONFIGURATION = {1,2,3,2,1,1,1};
+ //Standard configuration (rotors 1-3, reflector B, all three rotors set to position 1, rings too)
+ public static final int[] STANDARD_CONFIGURATION = {1, 2, 3, 2, 1, 1, 1, 0, 0, 0};
- /**
+ /**
* Create new Enigma with given configuration.
* If pbconf == null no plugs will be set (no scrambling in the plugboard).
* If conf == null the enigma will be set to STANDARD_CONFIGURATION.
- * @param pbconf two-dimensional array containing the chars symbolizing plugs that need to be switched over.
- * @param conf configuration of the enigma (a,b,c,d,e,f,g - a-c rotors, d reflector, e-g positions of the rotors)
- */
- public Enigma(char[][] pbconf, int[] conf) throws Plugboard.PlugAlreadyUsedException
- {
- if(conf!=null) setConfiguration(conf);
- else setConfiguration(Enigma.STANDARD_CONFIGURATION);
+ *
+ * @param pbconf two-dimensional array containing the chars symbolizing plugs that need to be switched over.
+ * @param conf configuration of the enigma (a,b,c,d,e,f,g - a-c rotors, d reflector, e-g positions of the rotors)
+ */
+ public Enigma(char[][] pbconf, int[] conf) throws Plugboard.PlugAlreadyUsedException
+ {
+ if (conf != null) setConfiguration(conf);
+ else setConfiguration(Enigma.STANDARD_CONFIGURATION);
this.setPlugboard(pbconf);
- }
+ }
- /**
- * Encrypt / Decrypt a given String
- * @param w Text to decrypt/encrypt
- * @return encrypted/decrypted string
- */
- public String encrypt(String w)
- {
+ /**
+ * Encrypt / Decrypt a given String
+ *
+ * @param w Text to decrypt/encrypt
+ * @return encrypted/decrypted string
+ */
+ public String encrypt(String w)
+ {
//output string
- String c = "";
- //for each char x in k
- for(int i=0; i=65 && x<=90) //If x in [A..Z]
- {
- c = c + x; //Append to String
- }
- //if x is special symbol
- else
- {
- if(x == '.' || x == ',' || x == '!' || x == '?' || x == ':')
- {
- //replace x with X and encrypt
- c = c + 'X';
- }
- }
- }
- return c;
- }
+ for (int i = 0; i < w.length(); i++)
+ {
+ char x = w.charAt(i);
+ if (x >= 65 && x <= 90) //If x in [A..Z]
+ {
+ c = c + x; //Append to String
+ }
+ //if x is special symbol
+ else
+ {
+ if (x == '.' || x == ',' || x == '!' || x == '?' || x == ':')
+ {
+ //replace x with X and encrypt
+ c = c + 'X';
+ }
+ }
+ }
+ return c;
+ }
- /**
- * Create Plugboard configuration from String.
+ /**
+ * Create Plugboard configuration from String.
* String must be in format XY,AZ and so on.
* X and Y are plugs, that will be switched over.
* Don't use plugs twice such as in AA or AB,CA. This will cause Exceptions.
- * @param p String
- * @return Array containing plugboard configuration
- */
- public static char[][] parsePlugs(String p) throws InvalidPlugboardConfigurationFormatException
- {
+ *
+ * @param p String
+ * @return Array containing plugboard configuration
+ */
+ public static char[][] parsePlugs(String p) throws InvalidPlugboardConfigurationFormatException
+ {
//Check, if empty
- if(p.length()==0)
+ if (p.length() == 0)
{
return null;
}
@@ -154,20 +158,19 @@ public class Enigma
//Check, whether input have had a correct length. Length+1 divided by 3 should be exactly how much fields there are in the array.
//(2 chars or 2 chars followed by any times a comma and two chars)
- if(in.length!=(p.length()+1)/3)
+ if (in.length != (p.length() + 1) / 3)
{
throw new InvalidPlugboardConfigurationFormatException("Error parsing plugs! Maybe you missed a ','?");
- }
- else
+ } else
{
//Create new 2 dimensional array for pairs of plugs
- char[][] plugs = new char[(p.length()+1)/3][2];
+ char[][] plugs = new char[(p.length() + 1) / 3][2];
//Fill the array
- int i=0;
- for(String x:in)
+ int i = 0;
+ for (String x : in)
{
//Check, whether string is not representing a pair
- if(x.length()!=2)
+ if (x.length() != 2)
{
throw new InvalidPlugboardConfigurationFormatException("Error parsing plugs! Maybe you didn't enter a pair somewhere?");
}
@@ -181,163 +184,167 @@ public class Enigma
}
return plugs;
}
- }
+ }
/**
* Set the plugboard to a new created object and give it the configuration
+ *
* @param c configuration
* @throws Plugboard.PlugAlreadyUsedException
*/
public void setPlugboard(char[][] c) throws Plugboard.PlugAlreadyUsedException
{
plugboard = new Plugboard();
- if(c!=null)
+ if (c != null)
{
//Set each plug pair
- for(char[] x : c)
+ for (char[] x : c)
{
- plugboard.setPlugPair(x[0],x[1]);
+ plugboard.setPlugPair(x[0], x[1]);
}
}
}
- /**
- * Set config of the enigma
- * TODO: Can't this be done in a more elegant way?
- * @param conf configuration
- */
- public void setConfiguration(int[] conf)
- {
- if(conf.length!=7)
- {
- setConfiguration(Enigma.STANDARD_CONFIGURATION);
- }
- else
- {
- int ro1 = conf[0];
- int ro2 = conf[1];
- int ro3 = conf[2];
- int ref = conf[3];
- int r1rot = 26+conf[4]-1;
- int r2rot = 26+conf[5]-1;
- int r3rot = 26+conf[6]-1;
+ /**
+ * Set config of the enigma
+ *
+ * @param conf configuration
+ */
+ public void setConfiguration(int[] conf)
+ {
+ if (conf.length != 10)
+ {
+ setConfiguration(Enigma.STANDARD_CONFIGURATION);
+ } else
+ {
+ int ro1 = conf[0];
+ int ro2 = conf[1];
+ int ro3 = conf[2];
+ int ref = conf[3];
+ int r1rot = 26 + conf[4] - 1;
+ int r2rot = 26 + conf[5] - 1;
+ int r3rot = 26 + conf[6] - 1;
+ int ro1Ring = conf[7];
+ int ro2Ring = conf[8];
+ int ro3Ring = conf[9];
- //Set first rotor
- switch(ro1)
- {
- case 1:
- {
- r1 = new Rotor('1',(r1rot)%26,0);
- break;
- }
- case 2:
- {
- r1 = new Rotor('2',(r1rot)%26,0);
- break;
- }
- case 3:
- {
- r1 = new Rotor('3',(r1rot)%26,0);
- break;
- }
- case 4:
- {
- r1 = new Rotor('4',(r1rot)%26,0);
- break;
- }
- case 5:
- {
- r1 = new Rotor('5',(r1rot)%26,0);
- break;
- }
- }
- //Set second rotor
- switch(ro2)
- {
- case 1:
- {
- r2 = new Rotor('1',(r2rot)%26,0);
- break;
- }
- case 2:
- {
- r2 = new Rotor('2',(r2rot)%26,0);
- break;
- }
- case 3:
- {
- r2 = new Rotor('3',(r2rot)%26,0);
- break;
- }
- case 4:
- {
- r2 = new Rotor('4',(r2rot)%26,0);
- break;
- }
- case 5:
- {
- r2 = new Rotor('5',(r2rot)%26,0);
- break;
- }
- }
- //Set third rotor
- switch(ro3)
- {
- case 1:
- {
- r3 = new Rotor('1',(r3rot)%26,0);
- break;
- }
- case 2:
- {
- r3 = new Rotor('2',(r3rot)%26,0);
- break;
- }
- case 3:
- {
- r3 = new Rotor('3',(r3rot)%26,0);
- break;
- }
- case 4:
- {
- r3 = new Rotor('4',(r3rot)%26,0);
- break;
- }
- case 5:
- {
- r3 = new Rotor('5',(r3rot)%26,0);
- break;
- }
- }
- //Set reflector
- switch(ref)
- {
- case 1:
- {
- reflector = new Rotor('A',0,0);
- break;
- }
- case 2:
- {
- reflector = new Rotor('B',0,0);
- break;
- }
- case 3:
- {
- reflector = new Rotor('C',0,0);
- break;
- }
- }
- }
- }
+ //Set first rotor
+ switch (ro1)
+ {
+ case 1:
+ {
+ r1 = new Rotor('1', (r1rot) % 26, ro1Ring);
+ break;
+ }
+ case 2:
+ {
+ r1 = new Rotor('2', (r1rot) % 26, ro1Ring);
+ break;
+ }
+ case 3:
+ {
+ r1 = new Rotor('3', (r1rot) % 26, ro1Ring);
+ break;
+ }
+ case 4:
+ {
+ r1 = new Rotor('4', (r1rot) % 26, ro1Ring);
+ break;
+ }
+ case 5:
+ {
+ r1 = new Rotor('5', (r1rot) % 26, ro1Ring);
+ break;
+ }
+ }
+ //Set second rotor
+ switch (ro2)
+ {
+ case 1:
+ {
+ r2 = new Rotor('1', (r2rot) % 26, ro2Ring);
+ break;
+ }
+ case 2:
+ {
+ r2 = new Rotor('2', (r2rot) % 26, ro2Ring);
+ break;
+ }
+ case 3:
+ {
+ r2 = new Rotor('3', (r2rot) % 26, ro2Ring);
+ break;
+ }
+ case 4:
+ {
+ r2 = new Rotor('4', (r2rot) % 26, ro2Ring);
+ break;
+ }
+ case 5:
+ {
+ r2 = new Rotor('5', (r2rot) % 26, ro2Ring);
+ break;
+ }
+ }
+ //Set third rotor
+ switch (ro3)
+ {
+ case 1:
+ {
+ r3 = new Rotor('1', (r3rot) % 26, ro3Ring);
+ break;
+ }
+ case 2:
+ {
+ r3 = new Rotor('2', (r3rot) % 26, ro3Ring);
+ break;
+ }
+ case 3:
+ {
+ r3 = new Rotor('3', (r3rot) % 26, ro3Ring);
+ break;
+ }
+ case 4:
+ {
+ r3 = new Rotor('4', (r3rot) % 26, ro3Ring);
+ break;
+ }
+ case 5:
+ {
+ r3 = new Rotor('5', (r3rot) % 26, ro3Ring);
+ break;
+ }
+ }
+ //Set reflector
+ switch (ref)
+ {
+ case 1:
+ {
+ reflector = new Rotor('A', 0, 0);
+ break;
+ }
+ case 2:
+ {
+ reflector = new Rotor('B', 0, 0);
+ break;
+ }
+ case 3:
+ {
+ reflector = new Rotor('C', 0, 0);
+ break;
+ }
+ }
+ }
+ }
/**
* Return the configuration, the enigma machine is in right NOW
+ *
* @return array containing configuration
*/
public int[] getConfiguration()
{
- int[] c = new int[7];
+ int[] c = new int[10];
{
c[0] = r1.getType();
c[1] = r2.getType();
@@ -346,6 +353,9 @@ public class Enigma
c[4] = r1.getCounter();
c[5] = r2.getCounter();
c[6] = r3.getCounter();
+ c[7] = r1.getRingsetting();
+ c[8] = r2.getRingsetting();
+ c[9] = r3.getRingsetting();
}
return c;
}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
index c788f44..9dc0de2 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java
@@ -1,6 +1,8 @@
package de.vanitasvitae.enigmandroid;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
@@ -12,40 +14,44 @@ import android.widget.Toast;
public class MainActivity extends Activity
{
- private Spinner w1;
- private Spinner w2;
- private Spinner w3;
+ private Spinner rotor1;
+ private Spinner rotor2;
+ private Spinner rotor3;
private Spinner reversingRotor;
- private Spinner w1pos;
- private Spinner w2pos;
- private Spinner w3pos;
+ private Spinner rotor1Position;
+ private Spinner rotor2Position;
+ private Spinner rotor3Position;
private EditText plugboard;
private EditText input;
private EditText output;
private Enigma enigma;
+ //memory for the ringsettings
+ private int[] ringsettings = {0,0,0};
+
@Override
- public void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState)
+ {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
-
this.initLayout();
this.reset();
}
@Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
this.getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
+ /**
+ * Handle Options menu clicks
+ */
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
int id = item.getItemId();
if (id == R.id.action_version)
{
@@ -53,60 +59,79 @@ public class MainActivity extends Activity
Toast.LENGTH_SHORT).show();
return true;
}
- else if(id == R.id.action_reset)
+ else if (id == R.id.action_reset)
{
this.reset();
+ Toast.makeText(getApplicationContext(), R.string.message_reset,
+ Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ else if (id == R.id.action_choose_ringstellung)
+ {
+ showRingsettingsDialog();
+ return true;
}
return super.onOptionsItemSelected(item);
}
- public void setEnigma(View v)
+ /**
+ * Updates the enigma to the chosen rotors and plugboard
+ *
+ * @param v View
+ */
+ public void updateEnigma(View v)
{
- int[] conf = new int[7];
- conf[0] = w1.getSelectedItemPosition()+1;
- conf[1] = w2.getSelectedItemPosition()+1;
- conf[2] = w3.getSelectedItemPosition()+1;
- conf[3] = reversingRotor.getSelectedItemPosition()+1;
- conf[4] = w1pos.getSelectedItemPosition()+1;
- conf[5] = w2pos.getSelectedItemPosition()+1;
- conf[6] = w3pos.getSelectedItemPosition()+1;
+ int[] conf = new int[10];
+ conf[0] = rotor1.getSelectedItemPosition() + 1;
+ conf[1] = rotor2.getSelectedItemPosition() + 1;
+ conf[2] = rotor3.getSelectedItemPosition() + 1;
+ conf[3] = reversingRotor.getSelectedItemPosition() + 1;
+ conf[4] = rotor1Position.getSelectedItemPosition() + 1;
+ conf[5] = rotor2Position.getSelectedItemPosition() + 1;
+ conf[6] = rotor3Position.getSelectedItemPosition() + 1;
+ conf[7] = ringsettings[0];
+ conf[8] = ringsettings[1];
+ conf[9] = ringsettings[2];
try
{
- enigma = new Enigma(null,null);
- }
- catch(Plugboard.PlugAlreadyUsedException e)
+ enigma = new Enigma(null, null);
+ } catch (Plugboard.PlugAlreadyUsedException e)
{
//There is nothing that could possibly go wrong here.
}
- char[][] pbconf = null;
+ char[][] plugboardConfiguration = null;
try
{
- pbconf = Enigma.parsePlugs(plugboard.getText().toString());
- }
- catch(Enigma.InvalidPlugboardConfigurationFormatException e)
+ plugboardConfiguration = Enigma.parsePlugs(plugboard.getText().toString());
+ } catch (Enigma.InvalidPlugboardConfigurationFormatException e)
{
- String error = this.getResources().getString(R.string.error_parsing_plugs)+": "+e.getMessage();
+ String error = this.getResources().getString(R.string.error_parsing_plugs) + ": " + e.getMessage();
Toast.makeText(getApplicationContext(), error,
- Toast.LENGTH_SHORT).show();
+ Toast.LENGTH_LONG).show();
}
try
{
enigma.setConfiguration(conf);
- enigma.setPlugboard(pbconf);
+ enigma.setPlugboard(plugboardConfiguration);
- }
- catch(Plugboard.PlugAlreadyUsedException e)
+ } catch (Plugboard.PlugAlreadyUsedException e)
{
Toast.makeText(this.getApplicationContext(), e.getMessage(),
- Toast.LENGTH_SHORT).show();
+ Toast.LENGTH_LONG).show();
}
}
- public void crypto(View v)
+ /**
+ * Set the chosen Configuration to the enigma, get the input string from the input textbox and prepare it,
+ * set the input to the prepared text, encrypt the prepared input and set the encrypted string to the
+ * output textbox and update the spinners to their new positions.
+ * @param v View
+ */
+ public void doCrypto(View v)
{
- setEnigma(null);
+ updateEnigma(null);
String m = input.getText().toString();
m = Enigma.prepare(m);
input.setText(m);
@@ -115,64 +140,72 @@ public class MainActivity extends Activity
}
+
+ /**
+ * Reset all the spinners and textboxes and the ringsettings memory
+ */
private void reset()
{
- w1.setSelection(0);
- w2.setSelection(1);
- w3.setSelection(2);
+ rotor1.setSelection(0);
+ rotor2.setSelection(1);
+ rotor3.setSelection(2);
reversingRotor.setSelection(1);
- w1pos.setSelection(0);
- w2pos.setSelection(0);
- w3pos.setSelection(0);
+ rotor1Position.setSelection(0);
+ rotor2Position.setSelection(0);
+ rotor3Position.setSelection(0);
+ ringsettings = new int[]{0,0,0};
plugboard.setText("");
input.setText("");
output.setText("");
}
+ /**
+ * Initialize the Layout
+ */
private void initLayout()
{
- w1 = (Spinner) findViewById(R.id.w1);
- ArrayAdapter w1adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_walzen, android.R.layout.simple_spinner_item);
- w1adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w1.setAdapter(w1adapter);
+ rotor1 = (Spinner) findViewById(R.id.rotor1);
+ ArrayAdapter rotor1Adapter = ArrayAdapter.createFromResource(this,
+ R.array.enigma_rotors, android.R.layout.simple_spinner_item);
+ rotor1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor1.setAdapter(rotor1Adapter);
- w2 = (Spinner) findViewById(R.id.w2);
- ArrayAdapter w2adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_walzen, android.R.layout.simple_spinner_item);
- w2adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w2.setAdapter(w2adapter);
+ rotor2 = (Spinner) findViewById(R.id.rotor2);
+ ArrayAdapter rotor2Adapter = ArrayAdapter.createFromResource(this,
+ R.array.enigma_rotors, android.R.layout.simple_spinner_item);
+ rotor2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor2.setAdapter(rotor2Adapter);
- w3 = (Spinner) findViewById(R.id.w3);
- ArrayAdapter w3adapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_walzen, android.R.layout.simple_spinner_item);
- w3adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w3.setAdapter(w3adapter);
+ rotor3 = (Spinner) findViewById(R.id.rotor3);
+ ArrayAdapter rotor3Adapter = ArrayAdapter.createFromResource(this,
+ R.array.enigma_rotors, android.R.layout.simple_spinner_item);
+ rotor3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor3.setAdapter(rotor3Adapter);
- reversingRotor = (Spinner) findViewById(R.id.ukw);
- ArrayAdapter ukwadapter = ArrayAdapter.createFromResource(this,
- R.array.enigma_ukw, android.R.layout.simple_spinner_item);
- ukwadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- reversingRotor.setAdapter(ukwadapter);
+ reversingRotor = (Spinner) findViewById(R.id.reflector);
+ ArrayAdapter relfectorAdapter = ArrayAdapter.createFromResource(this,
+ R.array.enigma_reflectors, android.R.layout.simple_spinner_item);
+ relfectorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ reversingRotor.setAdapter(relfectorAdapter);
- w1pos = (Spinner) findViewById(R.id.w1pos);
- ArrayAdapter w1posadapter = ArrayAdapter.createFromResource(this,
- R.array.positions, android.R.layout.simple_spinner_item);
- w1posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w1pos.setAdapter(w1posadapter);
+ rotor1Position = (Spinner) findViewById(R.id.rotor1position);
+ ArrayAdapter rotor1PositionAdapter = ArrayAdapter.createFromResource(this,
+ R.array.rotor_positions, android.R.layout.simple_spinner_item);
+ rotor1PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor1Position.setAdapter(rotor1PositionAdapter);
- w2pos = (Spinner) findViewById(R.id.w2pos);
- ArrayAdapter w2posadapter = ArrayAdapter.createFromResource(this,
- R.array.positions, android.R.layout.simple_spinner_item);
- w2posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w2pos.setAdapter(w2posadapter);
+ rotor2Position = (Spinner) findViewById(R.id.rotor2position);
+ ArrayAdapter rotor2PositionAdapter = ArrayAdapter.createFromResource(this,
+ R.array.rotor_positions, android.R.layout.simple_spinner_item);
+ rotor2PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor2Position.setAdapter(rotor2PositionAdapter);
- w3pos = (Spinner) findViewById(R.id.w3pos);
- ArrayAdapter w3posadapter = ArrayAdapter.createFromResource(this,
- R.array.positions, android.R.layout.simple_spinner_item);
- w3posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- w3pos.setAdapter(w3posadapter);
+ rotor3Position = (Spinner) findViewById(R.id.rotor3position);
+ ArrayAdapter rotor3PositionAdapter = ArrayAdapter.createFromResource(this,
+ R.array.rotor_positions, android.R.layout.simple_spinner_item);
+ rotor3PositionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ rotor3Position.setAdapter(rotor3PositionAdapter);
plugboard = (EditText) findViewById(R.id.plugboard);
input = (EditText) findViewById(R.id.input);
@@ -181,13 +214,67 @@ public class MainActivity extends Activity
input.requestFocus();
}
+ /**
+ * Update the Spinners to their new Positions
+ * @param c Configuration
+ */
public void updateSpinner(int[] c)
{
- w1.setSelection(c[0]-1);
- w2.setSelection(c[1]-1);
- w3.setSelection(c[2]-1);
- w1pos.setSelection(c[4]);
- w2pos.setSelection(c[5]);
- w3pos.setSelection(c[6]);
+ rotor1.setSelection(c[0] - 1);
+ rotor2.setSelection(c[1] - 1);
+ rotor3.setSelection(c[2] - 1);
+ rotor1Position.setSelection(c[4]);
+ rotor2Position.setSelection(c[5]);
+ rotor3Position.setSelection(c[6]);
+ }
+
+ /**
+ * Show the dialog where the user can pick the ringsettings and set them if the user doesnt abort.
+ */
+ public void showRingsettingsDialog()
+ {
+ View ringsettingsView = View.inflate(this, R.layout.dialog_ringsettings, null);
+
+ final Spinner ring1 = (Spinner) ringsettingsView.findViewById(R.id.rotor1ring);
+ ArrayAdapter ring1Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
+ ring1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ ring1.setAdapter(ring1Adapter);
+ ring1.setSelection(ringsettings[0]);
+
+ final Spinner ring2 = (Spinner) ringsettingsView.findViewById(R.id.rotor2ring);
+ ArrayAdapter ring2Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
+ ring2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ ring2.setAdapter(ring2Adapter);
+ ring2.setSelection(ringsettings[1]);
+
+ final Spinner ring3 = (Spinner) ringsettingsView.findViewById(R.id.rotor3ring);
+ ArrayAdapter ring3Adapter = ArrayAdapter.createFromResource(this, R.array.ring_positions, android.R.layout.simple_spinner_item);
+ ring3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ ring3.setAdapter(ring3Adapter);
+ ring3.setSelection(ringsettings[2]);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.title_ringsetting);
+ builder.setView(ringsettingsView)
+ .setCancelable(true)
+ .setPositiveButton(R.string.dialog_positiv, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ ringsettings = new int[]{ring1.getSelectedItemPosition(), ring2.getSelectedItemPosition(), ring3.getSelectedItemPosition()};
+ String message = getResources().getString(R.string.dialog_ringsettings_success) + " " + (ringsettings[2]+1) + ", " + (ringsettings[1]+1) + ", " + (ringsettings[0]+1) + ".";
+ Toast.makeText(getApplicationContext(), message,
+ Toast.LENGTH_LONG).show();
+ }
+ })
+ .setNegativeButton(R.string.dialog_negativ, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id)
+ {
+ dialog.cancel();
+ Toast.makeText(getApplicationContext(), R.string.dialog_ringsettings_abort,
+ Toast.LENGTH_SHORT).show();
+ }
+ }).show();
}
}
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java
index 2a5bc50..74e46e8 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java
@@ -2,94 +2,81 @@ package de.vanitasvitae.enigmandroid;
/**
* Class representing the plugboard
- * @author vanitasvitae
*
+ * @author vanitasvitae
*/
public class Plugboard
{
- //Plugboard
- // Q W E R T Z U I O
- // A S D F G H J K
- // P Y X C V B N M L
+ //Plugboard
+ // Q W E R T Z U I O
+ // A S D F G H J K
+ // P Y X C V B N M L
- //Array containing plugged pairs
- int[] pb;
- //Standard array to compare pb to.
- public static final int[] ref = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
- /**
- * Create new plugboard without any plugged pairs. (empty, no scrambling here)
- */
- public Plugboard()
- {
- pb = new int[26];
- resetPlugboard();
- }
-
- /**
- * En-/decrypt a char following the connections on the plugboard
- * @param x char to perform crypto on
- * @return en-/decrypted char
- */
- public int encrypt(int x)
- {
- return pb[x];
- }
-
- /**
- * Reset the plugboard (no plugged pairs)
- */
- public void resetPlugboard()
- {
- pb = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
- }
+ //Array containing plugged pairs
+ int[] pb;
+ //Standard array to compare pb to.
+ public static final int[] ref = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
/**
- * Set plugs given by 2 dimensional array
- * @param p configuration
- * @throws PlugAlreadyUsedException
+ * Create new plugboard without any plugged pairs. (empty, no scrambling here)
*/
- public void setPlugs(char[][] p) throws PlugAlreadyUsedException
- {
- for(char[] x : p)
- {
- if(x!=null)
- {
- this.setPlugPair(x[0], x[1]);
- }
- }
- }
- /**
- * Set a pair of plugs on the plugboard
- * @param a first Plug
- * @param b second Plug
- */
- public void setPlugPair(char a, char b) throws PlugAlreadyUsedException
- {
- //prevent to plug a plug to itself
- if(a==b)
+ public Plugboard()
+ {
+ pb = new int[26];
+ resetPlugboard();
+ }
+
+ /**
+ * En-/decrypt a char following the connections on the plugboard
+ *
+ * @param x char to perform crypto on
+ * @return en-/decrypted char
+ */
+ public int encrypt(int x)
+ {
+ return pb[x];
+ }
+
+ /**
+ * Reset the plugboard (no plugged pairs)
+ */
+ public void resetPlugboard()
+ {
+ pb = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
+ }
+
+ /**
+ * Set a pair of plugs on the plugboard
+ *
+ * @param a first Plug
+ * @param b second Plug
+ */
+ public void setPlugPair(char a, char b) throws PlugAlreadyUsedException
+ {
+ //prevent to plug a plug to itself
+ if (a == b)
{
- throw new PlugAlreadyUsedException("Unable to plug "+a +" to " +a);
+ throw new PlugAlreadyUsedException("Unable to plug " + a + " to " + a);
}
- int x = a-65;
- int y = b-65;
+ int x = a - 65;
+ int y = b - 65;
//Check, if plugs already plugged
- if(pb[x]!=ref[x])
- {
- throw new PlugAlreadyUsedException("Plug " + a + " used twice!");
- }
- else if(pb[y]!=ref[y])
+ if (pb[x] != ref[x])
+ {
+ throw new PlugAlreadyUsedException("Plug " + a + " used twice!");
+ } else if (pb[y] != ref[y])
{
throw new PlugAlreadyUsedException("Plug " + b + " used twice!");
}
//If everything is correct
- else
- {
+ else
+ {
//set the pair
- int c =pb[x];
- pb[x] = pb[y];
- pb[y] = c;
- }
- }
+ int c = pb[x];
+ pb[x] = pb[y];
+ pb[y] = c;
+ }
+ }
public static class PlugAlreadyUsedException extends Exception
{
diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java
index 468b5dc..dd4ae9e 100644
--- a/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java
+++ b/app/src/main/java/de/vanitasvitae/enigmandroid/Rotor.java
@@ -2,210 +2,237 @@ package de.vanitasvitae.enigmandroid;
/**
* Class representing a rotor of the Enigma machine (I-V,A-C)
- * @author vanitas
*
+ * @author vanitas
*/
public class Rotor
{
- // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
- //ABC: 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
- //Rotor1: 'E','K','M','F','L','G','D','Q','V','Z','N','T','O','W','Y','H','X','U','S','P','A','I','B','R','C','J'
- //Rotor2: 'A','J','D','K','S','I','R','U','X','B','L','H','W','T','M','C','Q','G','Z','N','P','Y','F','V','O','E'
- //Rotor3: 'B','D','F','H','J','L','C','P','R','T','X','V','Z','N','Y','E','I','W','G','A','K','M','U','S','Q','O'
- //Rotor4: 'E','S','O','V','P','Z','J','A','Y','Q','U','I','R','H','X','L','N','F','T','G','K','D','C','M','W','B'
- //Rotor5: 'V','Z','B','R','G','I','T','Y','U','P','S','D','N','H','L','X','A','W','M','J','Q','O','F','E','C','K'
- //Reversing Rotor A: AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
- //Reversing Rotor B: AY BR CU DH EQ FS GL IP JX KN MO TZ VW
- //Reversing Rotor C: AF BV CP DJ EI GO HY KR LZ MX NW QT SU
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
+ //ABC: 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
+ //Rotor1: 'E','K','M','F','L','G','D','Q','V','Z','N','T','O','W','Y','H','X','U','S','P','A','I','B','R','C','J'
+ //Rotor2: 'A','J','D','K','S','I','R','U','X','B','L','H','W','T','M','C','Q','G','Z','N','P','Y','F','V','O','E'
+ //Rotor3: 'B','D','F','H','J','L','C','P','R','T','X','V','Z','N','Y','E','I','W','G','A','K','M','U','S','Q','O'
+ //Rotor4: 'E','S','O','V','P','Z','J','A','Y','Q','U','I','R','H','X','L','N','F','T','G','K','D','C','M','W','B'
+ //Rotor5: 'V','Z','B','R','G','I','T','Y','U','P','S','D','N','H','L','X','A','W','M','J','Q','O','F','E','C','K'
+ //Reversing Rotor A: AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
+ //Reversing Rotor B: AY BR CU DH EQ FS GL IP JX KN MO TZ VW
+ //Reversing Rotor C: AF BV CP DJ EI GO HY KR LZ MX NW QT SU
- //Original rotors
- public static final Integer[] rotor1 = {4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9};
- public static final Integer[] rotor2 = {0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4};
- public static final Integer[] rotor3 = {1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14};
- public static final Integer[] rotor4 = {4,18,14,21,15,25,9,0,24,16,20,8,17,7,23,11,13,5,19,6,10,3,2,12,22,1};
- public static final Integer[] rotor5 = {21,25,1,17,6,8,19,24,20,15,18,3,13,7,11,23,0,22,12,9,16,14,5,4,2,10};
- //Original rotors backwards direction
- public static final Integer[] backwardsRotor1 = {20,22,24,6,0,3,5,15,21,25,1,4,2,10,12,19,7,23,18,11,17,8,13,16,14,9};
- public static final Integer[] backwardsRotor2 = {0,9,15,2,25,22,17,11,5,1,3,10,14,19,24,20,16,6,4,13,7,23,12,8,21,18};
- public static final Integer[] backwardsRotor3 = {19,0,6,1,15,2,18,3,16,4,20,5,21,13,25,7,24,8,23,9,22,11,17,10,14,12};
- public static final Integer[] backwardsRotor4 = {7,25,22,21,0,17,19,13,11,6,20,15,23,16,2,4,9,12,1,18,10,3,24,14,8,5};
- public static final Integer[] backwardsRotor5 = {16,2,24,11,23,22,4,13,5,19,25,14,18,12,21,9,20,3,10,6,8,0,17,15,7,1};
+ //Original rotors
+ public static final Integer[] rotor1 = {4, 10, 12, 5, 11, 6, 3, 16, 21, 25, 13, 19, 14, 22, 24, 7, 23, 20, 18, 15, 0, 8, 1, 17, 2, 9};
+ public static final Integer[] rotor2 = {0, 9, 3, 10, 18, 8, 17, 20, 23, 1, 11, 7, 22, 19, 12, 2, 16, 6, 25, 13, 15, 24, 5, 21, 14, 4};
+ public static final Integer[] rotor3 = {1, 3, 5, 7, 9, 11, 2, 15, 17, 19, 23, 21, 25, 13, 24, 4, 8, 22, 6, 0, 10, 12, 20, 18, 16, 14};
+ public static final Integer[] rotor4 = {4, 18, 14, 21, 15, 25, 9, 0, 24, 16, 20, 8, 17, 7, 23, 11, 13, 5, 19, 6, 10, 3, 2, 12, 22, 1};
+ public static final Integer[] rotor5 = {21, 25, 1, 17, 6, 8, 19, 24, 20, 15, 18, 3, 13, 7, 11, 23, 0, 22, 12, 9, 16, 14, 5, 4, 2, 10};
+ //Original rotors backwards direction
+ public static final Integer[] backwardsRotor1 = {20, 22, 24, 6, 0, 3, 5, 15, 21, 25, 1, 4, 2, 10, 12, 19, 7, 23, 18, 11, 17, 8, 13, 16, 14, 9};
+ public static final Integer[] backwardsRotor2 = {0, 9, 15, 2, 25, 22, 17, 11, 5, 1, 3, 10, 14, 19, 24, 20, 16, 6, 4, 13, 7, 23, 12, 8, 21, 18};
+ public static final Integer[] backwardsRotor3 = {19, 0, 6, 1, 15, 2, 18, 3, 16, 4, 20, 5, 21, 13, 25, 7, 24, 8, 23, 9, 22, 11, 17, 10, 14, 12};
+ public static final Integer[] backwardsRotor4 = {7, 25, 22, 21, 0, 17, 19, 13, 11, 6, 20, 15, 23, 16, 2, 4, 9, 12, 1, 18, 10, 3, 24, 14, 8, 5};
+ public static final Integer[] backwardsRotor5 = {16, 2, 24, 11, 23, 22, 4, 13, 5, 19, 25, 14, 18, 12, 21, 9, 20, 3, 10, 6, 8, 0, 17, 15, 7, 1};
- //Original reflector rotors A,B,C, D, E,F, G, H, I, J,K, L,M,N, O, P, Q, R, S, T, U, V,W, X,Y,Z
- public static final Integer[] reflectorA = {4,9,12,25,0,11,24,23,21,1,22,5,2,17,16,20,14,13,19,18,15,8,10,7,6,3};
- public static final Integer[] reflectorB = {24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19};
- public static final Integer[] reflectorC = {5,21,15,9,8,0,14,24,4,3,17,25,23,22,6,2,19,10,20,16,18,1,13,12,7,11};
+ //Original reflector rotors A,B,C, D, E,F, G, H, I, J,K, L,M,N, O, P, Q, R, S, T, U, V,W, X,Y,Z
+ public static final Integer[] reflectorA = {4, 9, 12, 25, 0, 11, 24, 23, 21, 1, 22, 5, 2, 17, 16, 20, 14, 13, 19, 18, 15, 8, 10, 7, 6, 3};
+ public static final Integer[] reflectorB = {24, 17, 20, 7, 16, 18, 11, 3, 15, 23, 13, 6, 14, 10, 12, 8, 4, 1, 5, 25, 2, 22, 21, 9, 0, 19};
+ public static final Integer[] reflectorC = {5, 21, 15, 9, 8, 0, 14, 24, 4, 3, 17, 25, 23, 22, 6, 2, 19, 10, 20, 16, 18, 1, 13, 12, 7, 11};
- //Atributes of the rotor
- private Integer[] rotor; //choose one of rotor1-5
- private Integer[] rrotor; //choose one of backwardsRotor1-5
- private int ringsetting;
+ //Attributes of the rotor
+ private Integer[] rotor; //choose one of rotor1-5
+ private Integer[] backwardsRotor; //choose one of backwardsRotor1-5
+ private int ringsetting;
private int turnOver;
- private int counter;
- private String name;
+ private int counter;
+ private String name;
private int type;
- /**
- * Create new Rotor (1 - 5 = normal rotor, -1 - -3 = reversing rotor)
- * @param type integer determines type
- * @param setting setting (rotation) of the rotor
- */
- public Rotor(char type, int setting, int ring)
- {
- this.ringsetting = ring%26;
- switch(type)
- {
- case '1':
- {
- this.rotor = rotor1;
- this.rrotor = backwardsRotor1;
- this.counter = setting;
- this.name="I";
- this.turnOver = 17; //"Royal"
- this.type = 1;
- break;
- }
- case '2':
- {
- this.rotor = rotor2;
- this.rrotor = backwardsRotor2;
- this.counter = setting;
- this.name="II";
- this.turnOver = 5; //"Flags"
- this.type = 2;
- break;
- }
- case '3':
- {
- this.rotor = rotor3;
- this.rrotor = backwardsRotor3;
- this.counter = setting;
- this.name="III";
- this.turnOver = 22; //"Wave"
- this.type = 3;
- break;
- }
- case '4':
- {
- this.rotor = rotor4;
- this.rrotor = backwardsRotor4;
- this.counter = setting;
- this.name="IV";
- this.turnOver = 10; //"Kings"
- this.type = 4;
- break;
- }
- case '5':
- {
- this.rotor = rotor5;
- this.rrotor = backwardsRotor5;
- this.counter = setting;
- this.name="V";
- this.turnOver = 0; //"Above"
- this.type = 5;
- break;
- }
- case 'A':
- {
- this.rotor = reflectorA;
- this.rrotor = null;
- this.counter = 0;
- this.name="A";
- this.type = 1;
- break;
- }
- case 'B':
- {
- this.rotor = reflectorB;
- this.rrotor = null;
- this.counter = 0;
- this.name="B";
- this.type = 2;
- break;
- }
- case 'C':
- {
- this.rotor = reflectorC;
- this.rrotor = null;
- this.counter = 0;
- this.name="C";
- this.type = 3;
- break;
- }
- }
- }
+ /**
+ * Create new Rotor (1 - 5 = normal rotor, -1 - -3 = reversing rotor)
+ *
+ * @param type integer determines type
+ * @param setting setting (rotation) of the rotor
+ */
+ public Rotor(char type, int setting, int ring)
+ {
+ this.ringsetting = ring;
+ switch (type)
+ {
+ case '1':
+ {
+ this.rotor = rotor1;
+ this.backwardsRotor = backwardsRotor1;
+ this.counter = setting;
+ this.name = "I";
+ this.turnOver = 17; //"Royal"
+ this.type = 1;
+ break;
+ }
+ case '2':
+ {
+ this.rotor = rotor2;
+ this.backwardsRotor = backwardsRotor2;
+ this.counter = setting;
+ this.name = "II";
+ this.turnOver = 5; //"Flags"
+ this.type = 2;
+ break;
+ }
+ case '3':
+ {
+ this.rotor = rotor3;
+ this.backwardsRotor = backwardsRotor3;
+ this.counter = setting;
+ this.name = "III";
+ this.turnOver = 22; //"Wave"
+ this.type = 3;
+ break;
+ }
+ case '4':
+ {
+ this.rotor = rotor4;
+ this.backwardsRotor = backwardsRotor4;
+ this.counter = setting;
+ this.name = "IV";
+ this.turnOver = 10; //"Kings"
+ this.type = 4;
+ break;
+ }
+ case '5':
+ {
+ this.rotor = rotor5;
+ this.backwardsRotor = backwardsRotor5;
+ this.counter = setting;
+ this.name = "V";
+ this.turnOver = 0; //"Above"
+ this.type = 5;
+ break;
+ }
+ case 'A':
+ {
+ this.rotor = reflectorA;
+ this.backwardsRotor = null;
+ this.counter = 0;
+ this.name = "A";
+ this.type = 1;
+ break;
+ }
+ case 'B':
+ {
+ this.rotor = reflectorB;
+ this.backwardsRotor = null;
+ this.counter = 0;
+ this.name = "B";
+ this.type = 2;
+ break;
+ }
+ case 'C':
+ {
+ this.rotor = reflectorC;
+ this.backwardsRotor = null;
+ this.counter = 0;
+ this.name = "C";
+ this.type = 3;
+ break;
+ }
+ }
+ }
- /**
- * encrypt in forward direction (forward means first half of the cycle through the rotors)
- * @param x incoming character
- * @return encrypted character
- */
- public int encryptForward(int x)
- {
- return this.rotor[(26+x+ringsetting)%26];
- }
+ /**
+ * encrypt in forward direction (forward means first half of the cycle through the rotors)
+ *
+ * @param x incoming character
+ * @return encrypted character
+ */
+ public int encryptForward(int x)
+ {
+ return this.rotor[(26 + x) % 26];
+ }
- /**encrypt in backward direction (coming from the reversing rotor)
- * @param x incoming character
- * @return encrypted character
- */
- public int encryptBackward(int x)
- {
- if(this.rrotor == null) return this.rotor[(26+x+ringsetting)%26];
- else return this.rrotor[(26+x)%26];
- }
+ /**
+ * encrypt in backward direction (coming from the reversing rotor)
+ *
+ * @param x incoming character
+ * @return encrypted character
+ */
+ public int encryptBackward(int x)
+ {
+ if (this.backwardsRotor == null) return this.rotor[(26 + x) % 26];
+ else return this.backwardsRotor[(26 + x) % 26];
+ }
- /**
- * return rotation of the rotor
- * @return rotation
- */
- public int getCounter()
- {
- return this.counter;
- }
+ /**
+ * return rotation of the rotor - the ringsetting
+ *
+ * @return rotation
+ */
+ public int getCounter()
+ {
+ return this.counter - this.getRingsetting();
+ }
- /**
- * increment rotation of the rotor by one.
- */
- public void incrementCounter()
- {
- this.counter = (this.counter+1)%26;
- }
+ /**
+ * increment rotation of the rotor by one.
+ */
+ public void incrementCounter()
+ {
+ this.counter = (this.counter + 1) % 26;
+ }
/**
* Return true, if rotor is at a position, where it turns over the next rotor
+ *
* @return boolean
*/
public boolean isAtTurnoverPosition()
{
- return this.getCounter() == this.turnOver;
+ return this.counter == this.turnOver;
}
+ /**
+ * The Double Turn Anomaly (deutsch: Doppelsprung Anomalie) is aa anomaly in the rotor movement caused by the mechanical implementation of the enigma.
+ * Whenever the rightmost rotor turns the middle rotor AND the middle rotor is only one move from turning the leftmost rotor, the middle rotor turns again with the next character.
+ * So technically there are only 26*25*26 possible rotor settings for any but firmly 3 rotors.
+ *
+ * @return boolean
+ */
+ public boolean doubleTurnAnomaly()
+ {
+ return this.counter == this.turnOver - 1;
+ }
+
+ @SuppressWarnings("unused")
+ /**
+ * Returns the position of the turnover notch
+ *
+ * @return turnOver
+ */
public int getTurnOver()
{
return this.turnOver;
}
+ @SuppressWarnings("unused")
/**
* Return the name of the rotor
* @return name
*/
- public String getName()
- {
- return name;
- }
+ public String getName()
+ {
+ return name;
+ }
+ @SuppressWarnings("unused")
/**
* Return ringsettings of the rotor
* @return ringsetting
*/
- public int getRingsetting()
- {
- return this.ringsetting;
- }
+ public int getRingsetting()
+ {
+ return this.ringsetting;
+ }
/**
* Returns the integer, which was used to create this rotor.
+ *
* @return the type of the rotor
*/
public int getType()
diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml
index 969d402..abd0e43 100644
--- a/app/src/main/res/layout-land/activity_main.xml
+++ b/app/src/main/res/layout-land/activity_main.xml
@@ -18,43 +18,43 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
- android:text="@string/hint_ukw"/>
+ android:text="@string/hint_reflector"/>
+ android:text="@string/hint_rotor3"/>
+ android:text="@string/hint_rotor2"/>
+ android:text="@string/hint_rotor1"/>
+ android:text="@string/hint_rotor3_position"/>
+ android:text="@string/hint_rotor2_position"/>
+ android:text="@string/hint_rotor1_position"/>
+ android:id="@+id/reflector">
+ android:id="@+id/rotor3">
+ android:id="@+id/rotor2">
+ android:id="@+id/rotor1">
+ android:id="@+id/rotor3position">
+ android:id="@+id/rotor2position">
+ android:id="@+id/rotor1position">
@@ -136,7 +136,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/text_layer"
android:id="@+id/button_crypt"
- android:onClick="crypto"
+ android:onClick="doCrypto"
android:text="@string/button_crypt"/>
@@ -151,7 +151,7 @@
android:layout_weight=".50"
android:layout_height="match_parent"
android:id="@+id/input"
- android:hint="@string/hint_enigma_usertype" />
+ android:hint="@string/hint_enigma_type_here" />
+ android:text="@string/hint_reflector"/>
+ android:text="@string/hint_rotor3"/>
+ android:text="@string/hint_rotor2"/>
+ android:text="@string/hint_rotor1"/>
+ android:id="@+id/reflector">
+ android:id="@+id/rotor3">
+ android:id="@+id/rotor2">
+ android:id="@+id/rotor1">
@@ -86,19 +86,19 @@
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
- android:text="@string/hint_w3pos"/>
+ android:text="@string/hint_rotor3_position"/>
+ android:text="@string/hint_rotor2_position"/>
+ android:text="@string/hint_rotor1_position"/>
+ android:id="@+id/rotor3position">
+ android:id="@+id/rotor2position">
+ android:id="@+id/rotor1position">
+ android:hint="@string/hint_enigma_type_here" />
diff --git a/app/src/main/res/layout/dialog_ringsettings.xml b/app/src/main/res/layout/dialog_ringsettings.xml
new file mode 100644
index 0000000..b051e3d
--- /dev/null
+++ b/app/src/main/res/layout/dialog_ringsettings.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 5ee41aa..59ac26d 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -7,7 +7,11 @@
android:orderInCategory="100"
android:showAsAction="never" />
+
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index a30c7dc..6615adb 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -5,34 +5,42 @@
Version
Zurücksetzen
Version
- Hier Tippen
+ Ringstellung
+ Wähle die Ringstellungen für die Walzen:
+ Hier Tippen
Enigma-Code
Steckerbrett (AZ,BE...)
- Walze 1
- Walze 2
- Walze 3
- Umkehr-\nWalze
- Position\nWalze 1
- Position\nWalze 2
- Position\nWalze 3
+ Walze 1
+ Walze 2
+ Walze 3
+ Umkehr-\nWalze
+ Position\nWalze 1
+ Position\nWalze 2
+ Position\nWalze 3
Ver-/Entschlüsseln
Fehler: Fehlerhafte Steckerbrettkonfiguration.
Kann Stecker nicht setzen:
Fehler: Einer oder mehrere dieser Stecker sind bereits in Benutzung:
+ Ringstellungen
+ OK
+ Abbrechen
+ Setze Ringe auf
+ Keine Änderungen
+ Enigma zurückgesetzt
-
+
- I
- II
- III
- IV
- V
-
+
- A
- B
- C
-
+
- A
- B
- C
@@ -60,4 +68,33 @@
- Y
- Z
+
+
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ - 6
+ - 7
+ - 8
+ - 9
+ - 10
+ - 11
+ - 12
+ - 13
+ - 14
+ - 15
+ - 16
+ - 17
+ - 18
+ - 19
+ - 20
+ - 21
+ - 22
+ - 23
+ - 24
+ - 25
+ - 26
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 38cd9f3..e6e77ec 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,38 +1,46 @@
- 0.1-17.02.2015
+ 0.1.1-18.02.2015
EnigmAndroid
Version
Reset
- Type here
+ Ringsettings
+ Choose ringsettings for the rotors:
+ Type here
EnigmaCode
Plugboard (AZ,BE...)
- R1
- R2
- R3
- RR
- PosR1
- PosR2
- PosR3
+ Rotor 1
+ Rotor 2
+ Rotor 3
+ Reflector
+ Position Rotor 1
+ Position Rotor 2
+ Position Rotor 3
En-/Decrypt!
Error: Can\'t interpret Plugboard Input.
Unable to plug
Error: One or more of these Plugs are already in use:
+ Ringsettings
+ OK
+ Cancel
+ Set Ringsettings to
+ No changes
+ Enigma reset
-
+
- I
- II
- III
- IV
- V
-
+
- A
- B
- C
-
+
- A
- B
- C
@@ -60,4 +68,32 @@
- Y
- Z
+
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ - 6
+ - 7
+ - 8
+ - 9
+ - 10
+ - 11
+ - 12
+ - 13
+ - 14
+ - 15
+ - 16
+ - 17
+ - 18
+ - 19
+ - 20
+ - 21
+ - 22
+ - 23
+ - 24
+ - 25
+ - 26
+
diff --git a/build/intermediates/model_data.bin b/build/intermediates/model_data.bin
index 17b1b00..629c369 100644
Binary files a/build/intermediates/model_data.bin and b/build/intermediates/model_data.bin differ