mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-11-24 21:32:06 +01:00
Fixed reappearing input by switching models, added Enigma K
This commit is contained in:
parent
c5a0b549b7
commit
5e584acede
18 changed files with 704 additions and 78 deletions
|
@ -1,7 +1,10 @@
|
|||
CHANGELOG ENIGMANDROID
|
||||
v0.1.7-not-yet-released
|
||||
*TODO:Fix about dialog (outdated manual)
|
||||
*Fixed about dialog (outdated manual)
|
||||
*TODO: Add Enigma Z (find Rotor wiring reference somewhere)
|
||||
*TODO: Add Enigma K
|
||||
*TODO: Rewrite InputPreparer using decorator pattern to allow user customization
|
||||
*
|
||||
|
||||
v0.1.6-10.09.2015<
|
||||
*Updated CHANGELOG (oops)
|
||||
|
|
|
@ -98,6 +98,9 @@ public class MainActivity extends Activity
|
|||
case "D":
|
||||
this.setContentView(R.layout.activity_main_d);
|
||||
break;
|
||||
case "K":
|
||||
this.setContentView(R.layout.activity_main_k);
|
||||
break;
|
||||
default:
|
||||
this.setContentView(R.layout.activity_main_i_m3);
|
||||
break;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
|
@ -30,7 +28,7 @@ public class Enigma_D extends Enigma {
|
|||
protected Rotor rotor2;
|
||||
protected Rotor rotor3;
|
||||
|
||||
protected Reflector.ReflectorEnigmaD reflector;
|
||||
protected Reflector.ReflectorEnigmaDKD reflector;
|
||||
|
||||
public Enigma_D()
|
||||
{
|
||||
|
@ -45,7 +43,7 @@ public class Enigma_D extends Enigma {
|
|||
this.rotor1 = Rotor.createRotor(11, 0, 0);
|
||||
this.rotor2 = Rotor.createRotor(12, 0, 0);
|
||||
this.rotor3 = Rotor.createRotor(13, 0, 0);
|
||||
this.reflector = new Reflector.ReflectorEnigmaD();
|
||||
this.reflector = new Reflector.ReflectorEnigmaDKD();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +97,7 @@ public class Enigma_D extends Enigma {
|
|||
this.rotor1 = Rotor.createRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
|
||||
this.rotor2 = Rotor.createRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
|
||||
this.rotor3 = Rotor.createRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
|
||||
this.reflector = new Reflector.ReflectorEnigmaD(Plugboard.parseConfigurationString(state.getConfigurationReflector()));
|
||||
this.reflector = new Reflector.ReflectorEnigmaDKD(Plugboard.parseConfigurationString(state.getConfigurationReflector()));
|
||||
this.reflector.setRotation(state.getRotationReflector());
|
||||
this.reflector.setRingSetting(state.getRingSettingReflector());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
|
||||
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
|
||||
|
||||
/**
|
||||
* Implementation of the Enigma machine of type K (Switzerland)
|
||||
* Copyright (C) 2015 Paul Schaub
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* @author vanitasvitae
|
||||
*/
|
||||
public class Enigma_K extends Enigma
|
||||
{
|
||||
protected Rotor entryWheel;
|
||||
protected Rotor rotor1;
|
||||
protected Rotor rotor2;
|
||||
protected Rotor rotor3;
|
||||
|
||||
protected Reflector reflector;
|
||||
|
||||
public Enigma_K()
|
||||
{
|
||||
super();
|
||||
machineType = "K";
|
||||
}
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
this.entryWheel = Rotor.createRotor(0, 0, 0);
|
||||
this.rotor1 = Rotor.createRotor(14, 0, 0);
|
||||
this.rotor2 = Rotor.createRotor(15, 0, 0);
|
||||
this.rotor3 = Rotor.createRotor(16, 0, 0);
|
||||
this.reflector = Reflector.createReflector(7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextState()
|
||||
{
|
||||
rotor1.rotate();
|
||||
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
|
||||
{
|
||||
rotor2.rotate();
|
||||
this.doAnomaly = rotor2.doubleTurnAnomaly();
|
||||
if (rotor2.isAtTurnoverPosition())
|
||||
{
|
||||
rotor3.rotate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char encryptChar(char k) {
|
||||
nextState();
|
||||
int x = ((int) k)-65; //Cast to int and remove Unicode Offset (A=65 in Unicode.)
|
||||
//Encryption
|
||||
//forward direction
|
||||
x = entryWheel.encryptForward(x);
|
||||
x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting());
|
||||
x = rotor1.encryptForward(x);
|
||||
x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting() + rotor2.getRotation() - rotor2.getRingSetting());
|
||||
x = rotor2.encryptForward(x);
|
||||
x = rotor1.normalize(x - rotor2.getRotation() + rotor2.getRingSetting() + rotor3.getRotation() - rotor3.getRingSetting());
|
||||
x = rotor3.encryptForward(x);
|
||||
x = rotor1.normalize(x - rotor3.getRotation() + rotor3.getRingSetting() + reflector.getRotation() - reflector.getRingSetting());
|
||||
//backward direction
|
||||
x = reflector.encrypt(x);
|
||||
x = rotor1.normalize(x + rotor3.getRotation() - rotor3.getRingSetting() - reflector.getRotation() + reflector.getRingSetting());
|
||||
x = rotor3.encryptBackward(x);
|
||||
x = rotor1.normalize(x + rotor2.getRotation() - rotor2.getRingSetting() - rotor3.getRotation() + rotor3.getRingSetting());
|
||||
x = rotor2.encryptBackward(x);
|
||||
x = rotor1.normalize(x + rotor1.getRotation() - rotor1.getRingSetting() - rotor2.getRotation() + rotor2.getRingSetting());
|
||||
x = rotor1.encryptBackward(x);
|
||||
x = rotor1.normalize(x - rotor1.getRotation() + rotor1.getRingSetting());
|
||||
x = entryWheel.encryptBackward(x);
|
||||
return (char) (x + 65); //Add Offset again, cast back to char and return
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(EnigmaStateBundle state)
|
||||
{
|
||||
this.entryWheel = Rotor.createRotor(state.getTypeEntryWheel(), 0, 0);
|
||||
this.rotor1 = Rotor.createRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
|
||||
this.rotor2 = Rotor.createRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
|
||||
this.rotor3 = Rotor.createRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
|
||||
this.reflector = Reflector.createReflector(state.getTypeReflector());
|
||||
this.reflector.setRotation(state.getRotationReflector());
|
||||
this.reflector.setRingSetting(state.getRingSettingReflector());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnigmaStateBundle getState() {
|
||||
EnigmaStateBundle state = new EnigmaStateBundle();
|
||||
|
||||
state.setTypeRotor1(rotor1.getNumber());
|
||||
state.setTypeRotor2(rotor2.getNumber());
|
||||
state.setTypeRotor3(rotor3.getNumber());
|
||||
|
||||
state.setRotationRotor1(rotor1.getRotation());
|
||||
state.setRotationRotor2(rotor2.getRotation());
|
||||
state.setRotationRotor3(rotor3.getRotation());
|
||||
|
||||
state.setRingSettingRotor1(rotor1.getRingSetting());
|
||||
state.setRingSettingRotor2(rotor2.getRingSetting());
|
||||
state.setRingSettingRotor3(rotor3.getRingSetting());
|
||||
|
||||
state.setTypeReflector(reflector.getNumber());
|
||||
state.setRotationReflector(reflector.getRotation());
|
||||
state.setRingSettingReflector(reflector.getRingSetting());
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,9 @@ public abstract class EditTextAdapter
|
|||
*/
|
||||
public String getText()
|
||||
{
|
||||
return content;
|
||||
if(editText.getText().length() != 0)
|
||||
return content;
|
||||
else return content = "";
|
||||
}
|
||||
|
||||
public String getModifiedText()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.vanitasvitae.enigmandroid.enigma.rotors;
|
||||
|
||||
import java.sql.Ref;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.enigma.Plugboard;
|
||||
|
@ -68,12 +69,14 @@ public class Reflector
|
|||
/**
|
||||
* Factory method to create reflectors.
|
||||
* @param type type of the created reflector
|
||||
* "A" -> ReflectorA
|
||||
* "B" -> ReflectorB
|
||||
* "C" -> ReflectorC
|
||||
* "ThinB" -> ReflectorThinB
|
||||
* "ThinC" -> ReflectorThinC
|
||||
* "ReflectorD" -> ReflectorEnigmaD
|
||||
* 1 -> ReflectorA
|
||||
* 2 -> ReflectorB
|
||||
* 3 -> ReflectorC
|
||||
* 4 -> ReflectorThinB
|
||||
* 5 -> ReflectorThinC
|
||||
* 6 -> ReflectorEnigmaD
|
||||
* 7 -> ReflectorK
|
||||
* 7 -> ReflectorT
|
||||
* default -> ReflectorB
|
||||
* @return Reflector
|
||||
*/
|
||||
|
@ -86,7 +89,9 @@ public class Reflector
|
|||
case 3: return new ReflectorC();
|
||||
case 4: return new ReflectorThinB();
|
||||
case 5: return new ReflectorThinC();
|
||||
case 6: return new ReflectorEnigmaD();
|
||||
case 6: return new ReflectorEnigmaDKD();
|
||||
case 7: return new ReflectorEnigmaK();
|
||||
case 8: return new ReflectorEnigmaT();
|
||||
default: return new ReflectorB();
|
||||
}
|
||||
}
|
||||
|
@ -209,24 +214,24 @@ public class Reflector
|
|||
}
|
||||
|
||||
/**
|
||||
* Plugable Reflector of the Enigma machine of type D
|
||||
* Pluggable Reflector of the Enigma machine of type D and KD
|
||||
* Standard wiring: AI,BM,CE,DT,FG,HR,JY,KS,LQ,NZ,OX,PW,UV
|
||||
* Has additional ringSetting and can rotate
|
||||
*/
|
||||
public static class ReflectorEnigmaD extends Reflector
|
||||
public static class ReflectorEnigmaDKD extends Reflector
|
||||
{
|
||||
public static final String defaultWiring = "AI,BM,CE,DT,FG,HR,JY,KS,LQ,NZ,OX,PW,UV";
|
||||
private Plugboard connections;
|
||||
private int ringSetting;
|
||||
private int rotation;
|
||||
public ReflectorEnigmaD()
|
||||
public ReflectorEnigmaDKD()
|
||||
{
|
||||
super("Ref-D", 6, null);
|
||||
connections = new Plugboard();
|
||||
reset();
|
||||
}
|
||||
|
||||
public ReflectorEnigmaD(int[][] conf)
|
||||
public ReflectorEnigmaDKD(int[][] conf)
|
||||
{
|
||||
super("Ref-D", 6, null);
|
||||
connections = new Plugboard(conf);
|
||||
|
@ -314,4 +319,23 @@ public class Reflector
|
|||
}
|
||||
}
|
||||
|
||||
private static class ReflectorEnigmaK extends Reflector
|
||||
{
|
||||
public ReflectorEnigmaK()
|
||||
{
|
||||
super("Ref-K", 7, new Integer[]{8,12,4,19,2,6,5,17,0,24,18,16,1,25,23,22,11,7,10,3,21,20,15,14,9,13});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reflector as used in the Enigma type T (Tirpitz)
|
||||
* G E K P B T A U M O C N I L J D X Z Y F H W V Q S R
|
||||
*/
|
||||
private static class ReflectorEnigmaT extends Reflector
|
||||
{
|
||||
public ReflectorEnigmaT()
|
||||
{
|
||||
super("Ref-T", 8, new Integer[]{6,4,10,15,1,19,0,20,12,14,2,13,8,11,9,3,23,25,24,5,7,22,21,16,18,17});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class Rotor
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case 0: return new EntryWheelD();
|
||||
case 0: return new EntryWheelDK();
|
||||
case 1: return new RotorI(rotation, ringSetting);
|
||||
case 2: return new RotorII(rotation, ringSetting);
|
||||
case 3: return new RotorIII(rotation, ringSetting);
|
||||
|
@ -91,6 +91,9 @@ public class Rotor
|
|||
case 11: return new RotorDI(rotation, ringSetting);
|
||||
case 12: return new RotorDII(rotation, ringSetting);
|
||||
case 13: return new RotorDIII(rotation, ringSetting);
|
||||
case 14: return new RotorKI(rotation, ringSetting);
|
||||
case 15: return new RotorKII(rotation, ringSetting);
|
||||
case 16: return new RotorKIII(rotation, ringSetting);
|
||||
|
||||
default: return new RotorI(rotation, ringSetting);
|
||||
}
|
||||
|
@ -414,9 +417,13 @@ public class Rotor
|
|||
}
|
||||
}
|
||||
|
||||
private static class EntryWheelD extends Rotor
|
||||
/**
|
||||
* EntryWheel as used in the Enigma models D, K
|
||||
* 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
|
||||
*/
|
||||
private static class EntryWheelDK extends Rotor
|
||||
{
|
||||
public EntryWheelD()
|
||||
public EntryWheelDK()
|
||||
{
|
||||
super("ETW-D", 0,
|
||||
new Integer[]{9,22,20,11,2,12,13,14,7,15,16,25,24,23,8,17,0,3,10,4,6,21,1,19,18,5},
|
||||
|
@ -484,4 +491,52 @@ public class Rotor
|
|||
new Integer[]{14}, ringSetting, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotor I as used in the Enigma Type K (Switzerland)
|
||||
* P E Z U O H X S C V F M T B G L R I N Q J W A Y D K
|
||||
* Turnover Z
|
||||
*/
|
||||
private static class RotorKI extends Rotor
|
||||
{
|
||||
public RotorKI(int rotation, int ringSetting)
|
||||
{
|
||||
super("K-I", 14,
|
||||
new Integer[]{15,4,25,20,14,7,23,18,2,21,5,12,19,1,6,11,17,8,13,16,9,22,0,24,3,10},
|
||||
new Integer[]{22,13,8,24,1,10,14,5,17,20,25,15,11,18,4,0,19,16,7,12,3,9,21,6,23,2},
|
||||
new Integer[]{25}, ringSetting, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotor II as used in the Enigma Type K (Switzerland)
|
||||
* Z O U E S Y D K F W P C I Q X H M V B L G N J R A T
|
||||
* Turnover F
|
||||
*/
|
||||
private static class RotorKII extends Rotor
|
||||
{
|
||||
public RotorKII(int rotation, int ringSetting)
|
||||
{
|
||||
super("K-II", 15,
|
||||
new Integer[]{25,14,20,4,18,24,3,10,5,22,15,2,8,16,23,7,12,21,1,11,6,13,9,17,0,19},
|
||||
new Integer[]{24,18,11,6,3,8,20,15,12,22,7,19,16,21,1,10,13,23,4,25,2,17,9,14,5,0},
|
||||
new Integer[]{5}, ringSetting, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotor III as used in the Enigma Type K (Switzerland)
|
||||
* E H R V X G A O B Q U S I M Z F L Y N W K T P D J C
|
||||
* Turnover O
|
||||
*/
|
||||
private static class RotorKIII extends Rotor
|
||||
{
|
||||
public RotorKIII(int rotation, int ringSetting)
|
||||
{
|
||||
super("K-III", 16,
|
||||
new Integer[]{4,7,17,21,23,6,0,14,1,16,20,18,8,12,25,5,11,24,13,22,10,19,15,3,9,2},
|
||||
new Integer[]{6,8,25,23,0,15,5,1,12,24,20,16,13,18,7,22,9,2,11,21,10,3,19,4,17,14},
|
||||
new Integer[]{14}, ringSetting, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ public abstract class LayoutContainer
|
|||
case "M3": return new LayoutContainer_M3();
|
||||
case "M4": return new LayoutContainer_M4();
|
||||
case "D": return new LayoutContainer_D();
|
||||
case "K": return new LayoutContainer_K();
|
||||
default: return new LayoutContainer_I();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ public class LayoutContainer_D extends LayoutContainer
|
|||
{
|
||||
enigma = new Enigma_D();
|
||||
setLayoutState(enigma.getState());
|
||||
outputView.setText("");
|
||||
inputView.setText("");
|
||||
output.setText("");
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -104,8 +104,8 @@ public class LayoutContainer_I extends LayoutContainer
|
|||
{
|
||||
enigma = new Enigma_I();
|
||||
setLayoutState(enigma.getState());
|
||||
outputView.setText("");
|
||||
inputView.setText("");
|
||||
output.setText("");
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,7 +143,8 @@ public class LayoutContainer_I extends LayoutContainer
|
|||
@Override
|
||||
public void showRingSettingsDialog()
|
||||
{
|
||||
new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRot().createRingSettingsDialog(state);
|
||||
new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRot().
|
||||
createRingSettingsDialog(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
package de.vanitasvitae.enigmandroid.layout;
|
||||
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import de.vanitasvitae.enigmandroid.R;
|
||||
import de.vanitasvitae.enigmandroid.enigma.Enigma;
|
||||
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
||||
import de.vanitasvitae.enigmandroid.enigma.Enigma_K;
|
||||
|
||||
/**
|
||||
* LayoutContainer for the Enigma Model K
|
||||
* This class contains the layout and controls the layout elements such as spinners and stuff
|
||||
* Copyright (C) 2015 Paul Schaub
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* @author vanitasvitae
|
||||
*/
|
||||
public class LayoutContainer_K extends LayoutContainer
|
||||
{
|
||||
private Enigma_K enigma;
|
||||
|
||||
protected Spinner rotor1View;
|
||||
protected Spinner rotor2View;
|
||||
protected Spinner rotor3View;
|
||||
|
||||
protected Spinner rotor1PositionView;
|
||||
protected Spinner rotor2PositionView;
|
||||
protected Spinner rotor3PositionView;
|
||||
protected Spinner reflectorPositionView;
|
||||
|
||||
public LayoutContainer_K()
|
||||
{
|
||||
super();
|
||||
main.setTitle("K - EnigmAndroid");
|
||||
this.resetLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enigma getEnigma() {
|
||||
return this.enigma;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeLayout() {
|
||||
this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
|
||||
this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
|
||||
this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
|
||||
this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
|
||||
this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
|
||||
this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
|
||||
this.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
|
||||
|
||||
Character[] rotorPositionArray = new Character[26];
|
||||
for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /**Fill with A..Z*/}
|
||||
|
||||
ArrayAdapter<CharSequence> rotor1Adapter = ArrayAdapter.createFromResource(main, R.array.rotors_1_3,
|
||||
android.R.layout.simple_spinner_item);
|
||||
rotor1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor1View.setAdapter(rotor1Adapter);
|
||||
ArrayAdapter<CharSequence> rotor2Adapter = ArrayAdapter.createFromResource(main, R.array.rotors_1_3,
|
||||
android.R.layout.simple_spinner_item);
|
||||
rotor2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor2View.setAdapter(rotor2Adapter);
|
||||
ArrayAdapter<CharSequence> rotor3Adapter = ArrayAdapter.createFromResource(main, R.array.rotors_1_3,
|
||||
android.R.layout.simple_spinner_item);
|
||||
rotor3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor3View.setAdapter(rotor3Adapter);
|
||||
|
||||
ArrayAdapter<Character> rotor1PositionAdapter = new ArrayAdapter<>(main.getApplicationContext(),
|
||||
android.R.layout.simple_spinner_item, rotorPositionArray);
|
||||
rotor1PositionAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor1PositionView.setAdapter(rotor1PositionAdapter);
|
||||
ArrayAdapter<Character> rotor2PositionAdapter = new ArrayAdapter<>(main.getApplicationContext(),
|
||||
android.R.layout.simple_spinner_item, rotorPositionArray);
|
||||
rotor2PositionAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor2PositionView.setAdapter(rotor2PositionAdapter);
|
||||
ArrayAdapter<Character> rotor3PositionAdapter = new ArrayAdapter<>(main.getApplicationContext(),
|
||||
android.R.layout.simple_spinner_item, rotorPositionArray);
|
||||
rotor3PositionAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
rotor3PositionView.setAdapter(rotor3PositionAdapter);
|
||||
|
||||
ArrayAdapter<Character> reflectorPositionAdapter = new ArrayAdapter<>(main.getApplicationContext(),
|
||||
android.R.layout.simple_spinner_item, rotorPositionArray);
|
||||
reflectorPositionAdapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
reflectorPositionView.setAdapter(reflectorPositionAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetLayout() {
|
||||
enigma = new Enigma_K();
|
||||
setLayoutState(enigma.getState());
|
||||
output.setText("");
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLayoutState(EnigmaStateBundle state)
|
||||
{
|
||||
this.state = state;
|
||||
this.rotor1View.setSelection(state.getTypeRotor1()-14);
|
||||
this.rotor2View.setSelection(state.getTypeRotor2()-14);
|
||||
this.rotor3View.setSelection(state.getTypeRotor3()-14);
|
||||
this.rotor1PositionView.setSelection(state.getRotationRotor1());
|
||||
this.rotor2PositionView.setSelection(state.getRotationRotor2());
|
||||
this.rotor3PositionView.setSelection(state.getRotationRotor3());
|
||||
this.reflectorPositionView.setSelection(state.getRotationReflector());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshState()
|
||||
{
|
||||
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 14);
|
||||
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 14);
|
||||
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 14);
|
||||
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
|
||||
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
|
||||
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
|
||||
state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showRingSettingsDialog()
|
||||
{
|
||||
new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
|
||||
createRingSettingsDialog(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidConfiguration()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -94,8 +94,8 @@ public class LayoutContainer_M3 extends LayoutContainer_I
|
|||
{
|
||||
enigma = new Enigma_M3();
|
||||
setLayoutState(enigma.getState());
|
||||
outputView.setText("");
|
||||
inputView.setText("");
|
||||
output.setText("");
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -129,8 +129,8 @@ public class LayoutContainer_M4 extends LayoutContainer
|
|||
public void resetLayout() {
|
||||
enigma = new Enigma_M4();
|
||||
setLayoutState(enigma.getState());
|
||||
outputView.setText("");
|
||||
inputView.setText("");
|
||||
output.setText("");
|
||||
input.setText("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
144
app/src/main/res/layout-land/activity_main_k.xml
Executable file
144
app/src/main/res/layout-land/activity_main_k.xml
Executable file
|
@ -0,0 +1,144 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lin_lay_names_1">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor3"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor2"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor1"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_reflector_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor3_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor2_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor1_position"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lin_lay_1"
|
||||
android:layout_below="@+id/lin_lay_names_1">
|
||||
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor3">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor2">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor1">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/reflector_position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor3position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor2position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor1position">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lin_lay_1"
|
||||
android:layout_above="@+id/buttons_lay"
|
||||
android:id="@+id/text_layer">
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".50"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/input"
|
||||
android:inputType="textNoSuggestions|textMultiLine"
|
||||
android:hint="@string/hint_enigma_type_here" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".50"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="none"
|
||||
android:textIsSelectable="true"
|
||||
android:id="@+id/output"
|
||||
android:hint="@string/hint_enigma_code"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttons_lay"
|
||||
android:layout_alignParentBottom="true">
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/button_crypt"
|
||||
android:onClick="doCrypto"
|
||||
android:text="@string/button_crypt"
|
||||
android:background="@drawable/button"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
162
app/src/main/res/layout/activity_main_k.xml
Executable file
162
app/src/main/res/layout/activity_main_k.xml
Executable file
|
@ -0,0 +1,162 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lin_lay_names_1">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor3"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor2"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lin_lay_1"
|
||||
android:layout_below="@+id/lin_lay_names_1">
|
||||
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor3">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor2">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor1">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_below="@+id/lin_lay_1"
|
||||
android:id="@+id/lin_lay_names_2">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_reflector_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor3_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor2_position"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hint_rotor1_position"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lin_lay_2"
|
||||
android:layout_below="@+id/lin_lay_names_2">
|
||||
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/reflector_position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor3position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor2position">
|
||||
</Spinner>
|
||||
<Spinner
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rotor1position">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lin_lay_2"
|
||||
android:layout_above="@+id/buttons_lay"
|
||||
android:id="@+id/text_layer">
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".50"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/input"
|
||||
android:inputType="textNoSuggestions|textMultiLine"
|
||||
android:hint="@string/hint_enigma_type_here" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".50"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="none"
|
||||
android:textIsSelectable="true"
|
||||
android:id="@+id/output"
|
||||
android:hint="@string/hint_enigma_code"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttons_lay"
|
||||
android:layout_alignParentBottom="true">
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/button_crypt"
|
||||
android:onClick="doCrypto"
|
||||
android:text="@string/button_crypt"
|
||||
android:background="@drawable/button"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -36,6 +36,11 @@
|
|||
<string name="dialog_ringsettings_abort">No changes</string>
|
||||
<string name="message_reset">Enigma reset</string>
|
||||
|
||||
<string-array translatable="false" name="rotors_1_3">
|
||||
<item>I</item>
|
||||
<item>II</item>
|
||||
<item>III</item>
|
||||
</string-array>
|
||||
<string-array translatable="false" name="rotors_1_5">
|
||||
<item>I</item>
|
||||
<item>II</item>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<item>M3</item>
|
||||
<item>M4</item>
|
||||
<item>D</item>
|
||||
<item>K</item>
|
||||
</string-array>
|
||||
<string name="pref_title_simulate_anomaly">Simulate Anomaly</string>
|
||||
<string name="pref_description_simulate_anomaly">The double step anomaly causes the middle rotor
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
Categories:Science & Education
|
||||
License:GPLv2
|
||||
Web Site:https://github.com/vanitasvitae/EnigmAndroid/wiki/EnigmAndroid
|
||||
Source Code:https://github.com/vanitasvitae/EnigmAndroid
|
||||
Issue Tracker:https://github.com/vanitasvitae/EnigmAndroid/issues
|
||||
Summary:Simulation of the Enigma Machine
|
||||
Description:
|
||||
Simulation of the famous Enigma cipher machine used in the Second World War.
|
||||
The Enigma Machine was a typewriter-like machine, which used a set of mechanical Rotors to achieve polyalphabetic substitution.
|
||||
|
||||
Features:
|
||||
* Authentic Rotors
|
||||
* Ringsettings
|
||||
* Double Step Anomaly
|
||||
* Working plugboard
|
||||
|
||||
More Information about the historical Enigma can be found on [https://de.wikipedia.org/wiki/Enigma_%28Maschine%29 Wikipedia]
|
||||
.
|
||||
|
||||
|
||||
Repo Type:git
|
||||
Repo:https://github.com/vanitasvitae/EnigmAndroid
|
||||
|
||||
Build:0.1.1-18.02.2015-beta,6
|
||||
commit=707cdfcff66aababce83af1769ba9d8527067c8d
|
||||
subdir=app
|
||||
gradle=yes
|
||||
|
||||
Build:0.1.1-23.02.2015-beta,7
|
||||
commit=965aee43dd998c7f0fc70093e53ac05fd7311eab
|
||||
subdir=app
|
||||
gradle=yes
|
||||
|
||||
Build:0.1.2-24.02.2015-beta,8
|
||||
commit=310e44029ae1ee3754c630d923cb8f5468ea26d3
|
||||
subdir=app
|
||||
gradle=yes
|
||||
|
||||
Build:0.1.3-14.03.2015-beta,9
|
||||
commit=v0.1.3-14.03.2015-beta
|
||||
subdir=app
|
||||
gradle=yes
|
||||
|
||||
Auto Update Mode:Version v%v
|
||||
Update Check Mode:Tags
|
||||
Current Version:0.1.3-14.03.2015-beta
|
||||
Current Version Code:9
|
||||
|
Loading…
Reference in a new issue