Major bug fixes and improvements

This commit is contained in:
VanitasVitae 2015-10-04 22:51:35 +02:00
parent 8bab418e2b
commit 992c9a924d
52 changed files with 1708 additions and 1473 deletions

View file

@ -3,7 +3,10 @@ v0.1.9-not-yet-released<
*Added option to share/receive configurations via QR-Code (ZXing Barcode Scanner)
*Prevent user from setting incomplete reflector wiring
*Add option to generate configuration from passphrase
*TODO: Encode content of QR-Code completely in Base26(A..Z)
*Reworked Enigma definition (available Rotors/Reflectors/Entrywheels
*Verified correct functionality of Enigma T
*TODO: Write tests to ensure correct functionality
*TODO: Migrate preferences to SettingsActivity
*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)

View file

@ -4,6 +4,7 @@
<application
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

View file

@ -434,7 +434,7 @@ public class IntentIntegrator {
/**
* Defaults to type "TEXT_TYPE".
* Defaults to name "TEXT_TYPE".
*
* @param text the text string to encode as a barcode
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
@ -450,7 +450,7 @@ public class IntentIntegrator {
* scan the text off the screen of the device.
*
* @param text the text string to encode as a barcode
* @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
* @param type name of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
* if a prompt was needed, or null otherwise
*/

View file

@ -5,6 +5,8 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
@ -13,11 +15,15 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import java.math.BigInteger;
import java.security.SecureRandom;
import de.vanitasvitae.enigmandroid.enigma.Enigma;
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
@ -50,16 +56,18 @@ public class MainActivity extends Activity
"https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
public static final String APP_ID = "EnigmAndroid";
LayoutContainer layoutContainer;
protected String prefMachineType;
protected boolean prefAnomaly;
protected String prefNumericLanguage;
protected String prefMessageFormatting;
private LayoutContainer layoutContainer;
private String prefMachineType;
private String prefNumericLanguage;
private String prefMessageFormatting;
private SecureRandom secureRandom;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
secureRandom = new SecureRandom();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
getStringArray(R.array.pref_alias_machine_type)[0]);
@ -115,7 +123,7 @@ public class MainActivity extends Activity
case "G31":
case "G312":
case "G260":
this.setContentView(R.layout.activity_main_g_k_t);
this.setContentView(R.layout.activity_main_g_k_r_t);
break;
default:
this.setContentView(R.layout.activity_main_i_m3);
@ -128,14 +136,13 @@ public class MainActivity extends Activity
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
this.setPrefMachineType(sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
getStringArray(R.array.pref_alias_machine_type)[0]));
this.setPrefAnomaly(sharedPreferences.getBoolean(SettingsActivity.PREF_ANOMALY, true));
this.setPrefNumericLanguage(sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
this.setPrefMessageFormatting(sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
getStringArray(R.array.pref_alias_message_formatting)[0]));
}
public void setPrefMachineType(String type)
private void setPrefMachineType(String type)
{
if(prefMachineType == null || !prefMachineType.equals(type))
{
@ -150,7 +157,7 @@ public class MainActivity extends Activity
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
layoutContainer.getInput().setText(savedInput);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
sharedPreferences.edit().putString(SettingsActivity.PREF_MACHINE_TYPE, type);
sharedPreferences.edit().putString(SettingsActivity.PREF_MACHINE_TYPE, type).apply();
}
}
@ -163,20 +170,6 @@ public class MainActivity extends Activity
return prefMachineType;
}
public void setPrefAnomaly(boolean anomaly)
{
if(prefAnomaly !=anomaly)
{
prefAnomaly = anomaly;
if(layoutContainer != null && layoutContainer.getEnigma() != null) layoutContainer.getEnigma().setPrefAnomaly(anomaly);
}
}
public boolean getPrefAnomaly()
{
return prefAnomaly;
}
public void setPrefNumericLanguage(String lang)
{
if(prefNumericLanguage == null || !prefNumericLanguage.equals(lang))
@ -213,6 +206,11 @@ public class MainActivity extends Activity
return prefMessageFormatting;
}
public SecureRandom getSecureRandom()
{
return this.secureRandom;
}
public void onDialogFinished(EnigmaStateBundle state)
{
layoutContainer.getEnigma().setState(state);
@ -288,7 +286,7 @@ public class MainActivity extends Activity
IntentIntegrator QRIntegrator = new IntentIntegrator(this);
layoutContainer.syncStateFromLayoutToEnigma();
Log.d(APP_ID, "Sharing configuration to QR: " + layoutContainer.getEnigma().stateToString());
QRIntegrator.shareText(layoutContainer.getEnigma().stateToString());
QRIntegrator.shareText(APP_ID+"/"+layoutContainer.getEnigma().stateToString());
return true;
}
else if(id == R.id.action_enter_seed)
@ -300,9 +298,9 @@ public class MainActivity extends Activity
}
/**
* Set the chosen Configuration to the enigma, get the input string from the input textbox and
* Set the chosen Configuration to the enigma, get the input string from the input text box 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.
* encrypted string to the output text box and update the spinners to their new positions.
* @param v View
*/
public void doCrypto(View v)
@ -314,10 +312,18 @@ public class MainActivity extends Activity
* Show a Dialog containing information about the app, license, usage, author and a link
* to the changelog
*/
public void showAboutDialog()
private void showAboutDialog()
{
final View aboutView = View.inflate(this, R.layout.dialog_about, null);
//Get and set Version code
PackageInfo pInfo = null;
try{ pInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);}
catch (PackageManager.NameNotFoundException e){ e.printStackTrace();}
String version = pInfo.versionName+ " ("+pInfo.versionCode+")";
TextView versionText = (TextView) aboutView.findViewById(R.id.about_version_section);
versionText.setText(version);
//Build and show dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.title_about_dialog);
builder.setView(aboutView)
@ -354,7 +360,6 @@ public class MainActivity extends Activity
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
this.setPrefMachineType(sharedPrefs.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources()
.getStringArray(R.array.pref_alias_machine_type)[0]));
this.setPrefAnomaly(sharedPrefs.getBoolean(SettingsActivity.PREF_ANOMALY, true));
this.setPrefNumericLanguage(sharedPrefs.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
this.setPrefMessageFormatting(sharedPrefs.getString(SettingsActivity.PREF_MESSAGE_FORMATTING,
@ -366,8 +371,10 @@ public class MainActivity extends Activity
if (scanResult != null) {
String content = scanResult.getContents();
if(content == null) Log.e(APP_ID, "Error! Received nothing from QR-Code!");
else Log.d(APP_ID, "Received "+content+" from QR-Code!");
else {
Log.d(APP_ID, "Received " + content + " from QR-Code!");
restoreStateFromCode(content);
}
}
}
}
@ -385,10 +392,12 @@ public class MainActivity extends Activity
else
{
mem = mem.substring((APP_ID+"/").length());
setPrefMachineType(Enigma.chooseEnigmaFromSave(mem));
BigInteger s = new BigInteger(mem, 16);
Log.d(APP_ID, s.toString());
setPrefMachineType(Enigma.chooseEnigmaFromSave(s));
updateContentView();
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
layoutContainer.getEnigma().restoreState(mem);
layoutContainer.getEnigma().restoreState(Enigma.removeDigit(s,20));
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
layoutContainer.syncStateFromEnigmaToLayout();
}
@ -412,7 +421,7 @@ public class MainActivity extends Activity
* Open the web page with the URL url
* @param url URL of the website
*/
public void openWebPage(String url) {
private void openWebPage(String url) {
Uri webPage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
if (intent.resolveActivity(getPackageManager()) != null) {

View file

@ -1,8 +1,14 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Random;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Main component of the Enigma machine
* This is the mostly abstract base of any enigma machine.
@ -26,24 +32,90 @@ import java.util.Random;
public abstract class Enigma
{
protected static String machineType;
protected int machineTypeOffset = 0;
protected boolean doAnomaly = false; //Has the time come to handle an anomaly?
protected boolean prefAnomaly; //Do you WANT to simulate the anomaly?
protected ArrayList<EntryWheel> availableEntryWheels;
protected ArrayList<Rotor> availableRotors;
protected ArrayList<Reflector> availableReflectors;
protected Random rand;
public Enigma(int off)
{
this.machineTypeOffset = off;
initialize();
}
public Enigma()
{
establishAvailableParts();
initialize();
}
public int getMachineTypeOffset()
/**
* In this method, available EntryWheels, Rotors and Reflectors can be defined.
*/
protected abstract void establishAvailableParts();
/**
* Add a Rotor to the ArrayList of available rotors for this machine.
* Also set the index of the Rotor.
* @param r Rotor
*/
protected void addAvailableRotor(Rotor r)
{
return machineTypeOffset;
if(availableRotors == null) availableRotors = new ArrayList<>();
availableRotors.add(availableRotors.size(), r.setIndex(availableRotors.size()));
}
protected void addAvailableEntryWheel(EntryWheel e)
{
if(availableEntryWheels == null) availableEntryWheels = new ArrayList<>();
availableEntryWheels.add(availableEntryWheels.size(), e.setIndex(availableEntryWheels.size()));
}
protected void addAvailableReflector(Reflector r)
{
if(availableReflectors == null) availableReflectors = new ArrayList<>();
availableReflectors.add(availableReflectors.size(), r.setIndex(availableReflectors.size()));
}
public ArrayList<EntryWheel> getAvailableEntryWheels()
{
return availableEntryWheels;
}
public ArrayList<Rotor> getAvailableRotors()
{
return availableRotors;
}
public ArrayList<Reflector> getAvailableReflectors()
{
return availableReflectors;
}
public EntryWheel getEntryWheel(int index)
{
if(availableEntryWheels == null || availableEntryWheels.size() == 0) return null;
return availableEntryWheels.get(index % availableEntryWheels.size()).getInstance();
}
public Rotor getRotor(int index)
{
if(availableRotors == null || availableRotors.size() == 0) return null;
return availableRotors.get(index % availableRotors.size()).getInstance();
}
public Rotor getRotor(int index, int rotation, int ringSetting)
{
return getRotor(index).setRotation(rotation).setRingSetting(ringSetting);
}
public Reflector getReflector(int index)
{
if(availableReflectors == null || availableReflectors.size() == 0) return null;
return availableReflectors.get(index % availableReflectors.size()).getInstance();
}
public Reflector getReflector(int index, int rotation, int ringSetting)
{
return getReflector(index).setRotation(rotation).setRingSetting(ringSetting);
}
/**
@ -85,7 +157,8 @@ public abstract class Enigma
*/
public void randomState()
{
this.rand = new SecureRandom();
this.rand = ((MainActivity) (MainActivity.ActivitySingleton.getInstance().getActivity()))
.getSecureRandom();
generateState();
}
@ -121,7 +194,7 @@ public abstract class Enigma
/**
* Set the rand into a certain state based on seed.
* Then set the enigmas state.
* @param seed
* @param seed passphrase
*/
public void setStateFromSeed(String seed)
{
@ -129,12 +202,13 @@ public abstract class Enigma
generateState();
}
public abstract void restoreState(String mem);
public abstract void restoreState(BigInteger mem);
public abstract String stateToString();
public static String numToMachineType(int n)
{
n = (12+(n+12)%12)%12; //Problem? Trolololo
switch (n) {
case 0: return "I";
case 1: return "M3";
@ -156,27 +230,14 @@ public abstract class Enigma
return numToMachineType(seed.hashCode() % 12);
}
public static String chooseEnigmaFromSave(String save)
public static String chooseEnigmaFromSave(BigInteger save)
{
int index = save.indexOf(":");
if(index != -1) save = save.substring(0, index);
long s = Long.valueOf(save);
return numToMachineType(getValue(s,12));
}
/**
* set prefAnomaly variable
* @param b boolean
*/
public void setPrefAnomaly(boolean b)
{
this.prefAnomaly = b;
return numToMachineType(getValue(save,20));
}
/**
* Return the type indicator of the enigma machine
* @return type
* Return the name indicator of the enigma machine
* @return name
*/
public String getMachineType()
{
@ -189,9 +250,10 @@ public abstract class Enigma
* @param d domain (max value) of the value
* @return value
*/
protected static int getValue(long s, int d)
public static int getValue(BigInteger s, int d)
{
return (int) ((s%d)+d)%d;
BigInteger o = s.mod(BigInteger.valueOf(d)).add(BigInteger.valueOf(d)).mod(BigInteger.valueOf(d));
return Integer.valueOf(o.toString());
}
/**
@ -200,9 +262,11 @@ public abstract class Enigma
* @param d domain (max value)
* @return trimmed source
*/
protected static long removeDigit(long s, int d)
public static BigInteger removeDigit(BigInteger s, int d)
{
return (s-(s%d))/d;
s = s.subtract(s.mod(BigInteger.valueOf(d)));
s = s.divide(BigInteger.valueOf(d));
return s;
}
/**
@ -212,11 +276,10 @@ public abstract class Enigma
* @param v actual value
* @return lengthened source
*/
protected static long addDigit(long s, int v, int b)
public static BigInteger addDigit(BigInteger s, int v, int b)
{
long x = s;
x*=b;
x+=(v%b);
return x;
s = s.multiply(BigInteger.valueOf(b));
s = s.add(BigInteger.valueOf(v % b));
return s;
}
}

View file

@ -1,11 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import de.vanitasvitae.enigmandroid.MainActivity;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Concrete implementation of an enigma machine of type D
* Concrete implementation of an enigma machine of name D
* This machine has a rewirable UKW, non changeable rotors.
* Copyright (C) 2015 Paul Schaub
@ -25,35 +27,46 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
* @author vanitasvitae
*/
public class Enigma_D extends Enigma {
protected Rotor entryWheel;
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
protected Reflector.ReflectorEnigma_D_KD_G31 reflector;
protected static int machineTypeOffset = 70;
public Enigma_D()
{
super();
machineType = "D";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_K_D_I(0, 0));
addAvailableRotor(new Rotor.Rotor_K_D_II(0, 0));
addAvailableRotor(new Rotor.Rotor_K_D_III(0, 0));
addAvailableReflector(new Reflector.ReflectorEnigma_D_KD_G31());
}
@Override
public void initialize()
{
this.entryWheel = Rotor.createRotor(1, 0, 0);
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.reflector = (Reflector.ReflectorEnigma_D_KD_G31) Reflector.createReflector(machineTypeOffset);
this.entryWheel = availableEntryWheels.get(0);
this.rotor1 = availableRotors.get(0);
this.rotor2 = availableRotors.get(1);
this.rotor3 = availableRotors.get(2);
this.reflector = availableReflectors.get(0);
}
@Override
public void nextState()
{
rotor1.rotate();
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
this.doAnomaly = rotor2.doubleTurnAnomaly();
@ -75,14 +88,12 @@ public class Enigma_D extends Enigma {
int ring3 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, rot3, ring3);
this.rotor1.setRotation(rot1).setRingSetting(ring1);
this.rotor2.setRotation(rot2).setRingSetting(ring2);
this.rotor3.setRotation(rot3).setRingSetting(ring3);
this.reflector = (Reflector.ReflectorEnigma_D_KD_G31) Reflector.createReflector(machineTypeOffset);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.reflector.setConfiguration(Plugboard.seedToReflectorConfiguration(rand));
this.reflector.setRotation(rotRef).setRingSetting(ringRef)
.setConfiguration(Plugboard.seedToReflectorConfiguration(rand));
}
@Override
@ -116,14 +127,14 @@ public class Enigma_D extends Enigma {
@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 = new Reflector.ReflectorEnigma_D_KD_G31();
this.reflector.setConfiguration(state.getConfigurationReflector());
this.reflector.setRotation(state.getRotationReflector());
this.reflector.setRingSetting(state.getRingSettingReflector());
this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
this.reflector = getReflector(state.getTypeReflector(),
state.getRotationReflector(),
state.getRingSettingReflector())
.setConfiguration(state.getConfigurationReflector());
}
@Override
@ -131,11 +142,11 @@ public class Enigma_D extends Enigma {
{
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeEntryWheel(entryWheel.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -145,7 +156,7 @@ public class Enigma_D extends Enigma {
state.setRingSettingRotor2(rotor2.getRingSetting());
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setRotationReflector(reflector.getRotation());
state.setRingSettingReflector(reflector.getRingSetting());
state.setConfigurationReflector(reflector.getConfiguration());
@ -154,12 +165,8 @@ public class Enigma_D extends Enigma {
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
String reflectorConf = mem.substring(mem.lastIndexOf(":r")+2);
long s = Long.valueOf(mem.substring(0, mem.indexOf(":r")));
s = removeDigit(s, 20); //Remove machine type
int rot1 = getValue(s, 26);
s = removeDigit(s, 26);
int ring1 = getValue(s, 26);
@ -175,20 +182,19 @@ public class Enigma_D extends Enigma {
int rotRef = getValue(s, 26);
s = removeDigit(s, 26);
int ringRef = getValue(s, 26);
s = removeDigit(s, 26);
this.rotor1 = Rotor.createRotor(machineTypeOffset, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, rot3, ring3);
this.reflector = (Reflector.ReflectorEnigma_D_KD_G31) Reflector.createReflector(machineTypeOffset);
this.reflector.setConfiguration(Plugboard.stringToConfiguration(reflectorConf));
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.rotor1 = getRotor(0, rot1, ring1);
this.rotor2 = getRotor(1, rot2, ring2);
this.rotor3 = getRotor(2, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
this.reflector.setConfiguration(s);
}
@Override
public String stateToString() {
String save = MainActivity.APP_ID+"/";
long s = reflector.getRingSetting();
BigInteger s = Plugboard.configurationToBigInteger(reflector.getConfiguration());
s = addDigit(s, reflector.getRingSetting(), 26);
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
@ -197,9 +203,6 @@ public class Enigma_D extends Enigma {
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, 6, 20); //Machine #6
save = save+s;
save = save + ":r" + Plugboard.configurationToString(getState().getConfigurationReflector());
return save;
return s.toString(16);
}
}

View file

@ -1,9 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import de.vanitasvitae.enigmandroid.MainActivity;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type G31 (Abwehr)
* Implementation of the Enigma machine of name G31 (Abwehr)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -25,16 +29,24 @@ public class Enigma_G260 extends Enigma_G31
{
public Enigma_G260()
{
super(60);
super();
machineType = "G260";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_G260_I(0, 0));
addAvailableRotor(new Rotor.Rotor_G260_II(0, 0));
addAvailableRotor(new Rotor.Rotor_G260_III(0, 0));
addAvailableReflector(new Reflector.Reflector_K_G260());
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long s = reflector.getRingSetting();
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
@ -43,13 +55,12 @@ public class Enigma_G260 extends Enigma_G31
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 5, 20); //Machine #5
save = save+s;
return save;
return s.toString(16);
}
}

View file

@ -1,13 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import android.util.Log;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type G31 (Abwehr)
* Implementation of the Enigma machine of name G31 (Abwehr)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -27,37 +27,41 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_G31 extends Enigma
{
protected Rotor entryWheel;
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
public Enigma_G31(int off)
{
super(off);
}
public Enigma_G31()
{
super(40);
super();
machineType = "G31";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_G31_I(0, 0));
addAvailableRotor(new Rotor.Rotor_G31_II(0, 0));
addAvailableRotor(new Rotor.Rotor_G31_III(0, 0));
addAvailableReflector(new Reflector.ReflectorEnigma_D_KD_G31());
}
@Override
public void initialize()
{
this.entryWheel = Rotor.createRotor(1, 0, 0);
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset + 1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset + 2, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0);
this.rotor2 = getRotor(1);
this.rotor3 = getRotor(2);
this.reflector = getReflector(0);
}
@Override
public void nextState()
{
Log.d("Anomaly",""+prefAnomaly+","+doAnomaly);
rotor1.rotate();
if (rotor1.isAtTurnoverPosition())
{
@ -75,7 +79,7 @@ public class Enigma_G31 extends Enigma
protected void generateState()
{
int r1, r2=-1, r3=-1;
int r1, r2=-1, r3;
r1 = rand.nextInt(3);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
r3 = 3 - r1 - r2;
@ -89,12 +93,11 @@ public class Enigma_G31 extends Enigma
int ring3 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
reflector.setRotation(rotRef);
reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
@ -127,24 +130,23 @@ public class Enigma_G31 extends Enigma
@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());
this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
this.reflector = getReflector(state.getTypeReflector(),
state.getRotationReflector(), state.getRingSettingReflector());
}
@Override
public EnigmaStateBundle getState() {
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeEntryWheel(entryWheel.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -154,7 +156,7 @@ public class Enigma_G31 extends Enigma
state.setRingSettingRotor2(rotor2.getRingSetting());
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setRotationReflector(reflector.getRotation());
state.setRingSettingReflector(reflector.getRingSetting());
@ -162,17 +164,14 @@ public class Enigma_G31 extends Enigma
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
long s = Long.valueOf(mem);
s = removeDigit(s, 20); //Remove machine type
int r1 = getValue(s, 10);
s = removeDigit(s, 10);
int r2 = getValue(s, 10);
s = removeDigit(s, 10);
int r3 = getValue(s, 10);
s = removeDigit(s, 10);
int r1 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int r2 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int r3 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int rot1 = getValue(s, 26);
s = removeDigit(s, 26);
@ -191,19 +190,17 @@ public class Enigma_G31 extends Enigma
int ringRef = getValue(s, 26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long s = reflector.getRingSetting();
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
@ -212,13 +209,11 @@ public class Enigma_G31 extends Enigma
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 3, 20); //Machine #3
save = save+s;
return save;
return s.toString(16);
}
}

View file

@ -1,9 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import de.vanitasvitae.enigmandroid.MainActivity;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type G31 (Abwehr)
* Implementation of the Enigma machine of name G31 (Abwehr)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -25,15 +29,24 @@ public class Enigma_G312 extends Enigma_G31
{
public Enigma_G312()
{
super(50);
super();
machineType = "G312";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_G312_I(0, 0));
addAvailableRotor(new Rotor.Rotor_G312_II(0, 0));
addAvailableRotor(new Rotor.Rotor_G312_III(0, 0));
addAvailableReflector(new Reflector.Reflector_G312());
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long s = reflector.getRingSetting();
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
@ -42,13 +55,12 @@ public class Enigma_G312 extends Enigma_G31
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 4, 20); //Machine #4
save = save+s;
return save;
return s.toString(16);
}
}

View file

@ -1,11 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import de.vanitasvitae.enigmandroid.MainActivity;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Concrete implementation of an enigma machine of type I
* Concrete implementation of an enigma machine of name I
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -25,14 +27,13 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_I extends Enigma
{
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
protected Plugboard plugboard;
protected static int machineTypeOffset = 10;
public Enigma_I()
{
@ -40,21 +41,35 @@ public class Enigma_I extends Enigma
machineType = "I";
}
@Override
protected void establishAvailableParts() {
addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
addAvailableRotor(new Rotor.Rotor_I(0, 0));
addAvailableRotor(new Rotor.Rotor_II(0,0));
addAvailableRotor(new Rotor.Rotor_III(0,0));
addAvailableRotor(new Rotor.Rotor_IV(0,0));
addAvailableRotor(new Rotor.Rotor_V(0,0));
addAvailableReflector(new Reflector.Reflector_A());
addAvailableReflector(new Reflector.Reflector_B());
addAvailableReflector(new Reflector.Reflector_C());
}
@Override
public void initialize()
{
this.plugboard= new Plugboard();
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0, 0, 0);
this.rotor2 = getRotor(1, 0, 0);
this.rotor3 = getRotor(2, 0, 0);
this.reflector = getReflector(0);
}
@Override
public void nextState()
{
rotor1.rotate();
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
this.doAnomaly = rotor2.doubleTurnAnomaly();
@ -67,10 +82,10 @@ public class Enigma_I extends Enigma
@Override
protected void generateState() {
int rotor1, rotor2=-1, rotor3=-1;
rotor1 = rand.nextInt(5);
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(5);
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(5);
int r1, r2=-1, r3=-1;
r1 = rand.nextInt(5);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(5);
while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(5);
int ref = rand.nextInt(3);
int rot1 = rand.nextInt(26);
@ -80,10 +95,10 @@ public class Enigma_I extends Enigma
int ring2 = rand.nextInt(26);
int ring3 = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + rotor1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + rotor2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + rotor3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset + ref);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(ref);
this.plugboard = new Plugboard();
plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
@ -97,6 +112,7 @@ public class Enigma_I extends Enigma
//Encryption
//forward direction
x = plugboard.encrypt(x);
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());
@ -113,6 +129,7 @@ public class Enigma_I extends Enigma
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);
x = plugboard.encrypt(x);
return (char) (x + 65); //Add Offset again, cast back to char and return
}
@ -121,10 +138,11 @@ public class Enigma_I extends Enigma
public void setState(EnigmaStateBundle state)
{
plugboard.setConfiguration(state.getConfigurationPlugboard());
rotor1 = Rotor.createRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
rotor2 = Rotor.createRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
rotor3 = Rotor.createRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
reflector = Reflector.createReflector(state.getTypeReflector());
entryWheel = getEntryWheel(state.getTypeEntryWheel());
rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
reflector = getReflector(state.getTypeReflector());
}
@Override
@ -134,11 +152,13 @@ public class Enigma_I extends Enigma
state.setConfigurationPlugboard(plugboard.getConfiguration());
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeReflector(reflector.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setTypeReflector(reflector.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -152,20 +172,16 @@ public class Enigma_I extends Enigma
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
s = removeDigit(s, 20); //Remove machine type
int r1 = getValue(s, 10);
s = removeDigit(s, 10);
int r2 = getValue(s, 10);
s = removeDigit(s, 10);
int r3 = getValue(s, 10);
s = removeDigit(s, 10);
int ref = getValue(s, 10);
s = removeDigit(s, 10);
int r1 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int r2 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int r3 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int ref = getValue(s, availableReflectors.size());
s = removeDigit(s, availableReflectors.size());
int rot1 = getValue(s, 26);
s = removeDigit(s, 26);
int ring1 = getValue(s, 26);
@ -177,32 +193,33 @@ public class Enigma_I extends Enigma
int rot3 = getValue(s, 26);
s = removeDigit(s, 26);
int ring3 = getValue(s, 26);
s = removeDigit(s, 26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset + ref);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(ref);
this.plugboard = new Plugboard();
plugboard.setConfiguration(Plugboard.stringToConfiguration(plugboardConf));
plugboard.setConfiguration(s);
}
@Override
public String stateToString() {
String save = MainActivity.APP_ID+"/";
long s = rotor3.getRingSetting();
BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
s = addDigit(s, rotor2.getRingSetting(), 26);
s = addDigit(s, rotor2.getRotation(), 26);
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, reflector.getIndex(), availableReflectors.size());
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 0, 20); //Machine #0
save = save+s;
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
return save;
return s.toString(16);
}
}

View file

@ -1,17 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import android.app.Activity;
import android.util.Log;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type K
* Implementation of the Enigma machine of name K
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -31,38 +27,43 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_K extends Enigma
{
protected Rotor entryWheel;
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
public Enigma_K(int off)
{
super(off);
}
public Enigma_K()
{
super(80);
super();
machineType = "K";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_K_D_I(0, 0));
addAvailableRotor(new Rotor.Rotor_K_D_II(0,0));
addAvailableRotor(new Rotor.Rotor_K_D_III(0,0));
addAvailableReflector(new Reflector.Reflector_K_G260());
}
@Override
public void initialize()
{
this.entryWheel = Rotor.createRotor(1, 0, 0);
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0, 0, 0);
this.rotor2 = getRotor(1, 0, 0);
this.rotor3 = getRotor(2, 0, 0);
this.reflector = getReflector(0);
}
@Override
public void nextState()
{
rotor1.rotate();
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
this.doAnomaly = rotor2.doubleTurnAnomaly();
@ -75,10 +76,10 @@ public class Enigma_K extends Enigma
@Override
protected void generateState() {
int rotor1, rotor2=-1, rotor3=-1;
rotor1 = rand.nextInt(3);
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
rotor3 = 3 - rotor1 - rotor2;
int r1, r2=-1, r3;
r1 = rand.nextInt(3);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
r3 = 3 - r1 - r2;
int rot1 = rand.nextInt(26);
int rot2 = rand.nextInt(26);
@ -89,12 +90,11 @@ public class Enigma_K extends Enigma
int ring3 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + rotor1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + rotor2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + rotor3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
reflector.setRotation(rotRef);
reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
@ -127,13 +127,11 @@ public class Enigma_K extends Enigma
@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());
this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
}
@Override
@ -141,11 +139,11 @@ public class Enigma_K extends Enigma
{
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeEntryWheel(entryWheel.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -155,7 +153,7 @@ public class Enigma_K extends Enigma
state.setRingSettingRotor2(rotor2.getRingSetting());
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setRotationReflector(reflector.getRotation());
state.setRingSettingReflector(reflector.getRingSetting());
@ -163,16 +161,14 @@ public class Enigma_K extends Enigma
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
long s = Long.valueOf(mem);
s = removeDigit(s,20); //Remove machine type
int r1 = getValue(s,10);
s = removeDigit(s,10);
int r2 = getValue(s,10);
s = removeDigit(s,10);
int r3 = getValue(s,10);
s = removeDigit(s,10);
int r1 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r2 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r3 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int rot1 = getValue(s,26);
s = removeDigit(s,26);
@ -190,32 +186,29 @@ public class Enigma_K extends Enigma
s = removeDigit(s,26);
int ringRef = getValue(s,26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long t = reflector.getRingSetting();
t = addDigit(t, reflector.getRotation(), 26);
t = addDigit(t, rotor3.getRingSetting(),26);
t = addDigit(t, rotor3.getRotation(), 26);
t = addDigit(t, rotor2.getRingSetting(),26);
t = addDigit(t, rotor2.getRotation(), 26);
t = addDigit(t, rotor1.getRingSetting(), 26);
t = addDigit(t, rotor1.getRotation(), 26);
t = addDigit(t, rotor3.getNumber(), 10);
t = addDigit(t, rotor2.getNumber(), 10);
t = addDigit(t, rotor1.getNumber(), 10);
t = addDigit(t, 7, 20); //Machine #7
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(),26);
s = addDigit(s, rotor3.getRotation(), 26);
s = addDigit(s, rotor2.getRingSetting(),26);
s = addDigit(s, rotor2.getRotation(), 26);
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 7, 20); //Machine #7
save = save+t;
return save;
return s.toString(16);
}
}

View file

@ -1,14 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.util.Random;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type K (Switzerland, Airforce)
* Implementation of the Enigma machine of name K (Switzerland, Airforce)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -30,28 +29,36 @@ public class Enigma_K_Swiss_Airforce extends Enigma_K
{
public Enigma_K_Swiss_Airforce()
{
super(100);
super();
machineType = "KSA";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_I(0,0));
addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_II(0,0));
addAvailableRotor(new Rotor.Rotor_K_Swiss_Airforce_III(0,0));
addAvailableReflector(new Reflector.Reflector_K_G260());
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long t = reflector.getRingSetting();
t = addDigit(t, reflector.getRotation(), 26);
t = addDigit(t, rotor3.getRingSetting(),26);
t = addDigit(t, rotor3.getRotation(), 26);
t = addDigit(t, rotor2.getRingSetting(),26);
t = addDigit(t, rotor2.getRotation(), 26);
t = addDigit(t, rotor1.getRingSetting(), 26);
t = addDigit(t, rotor1.getRotation(), 26);
t = addDigit(t, rotor3.getNumber(), 10);
t = addDigit(t, rotor2.getNumber(), 10);
t = addDigit(t, rotor1.getNumber(), 10);
t = addDigit(t, 9, 20); //Machine #9
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(),26);
s = addDigit(s, rotor3.getRotation(), 26);
s = addDigit(s, rotor2.getRingSetting(),26);
s = addDigit(s, rotor2.getRotation(), 26);
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 9, 20); //Machine #9
save = save+t;
return save;
return s.toString(16);
}
}

View file

@ -1,14 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.util.Random;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type K (Switzerland)
* Implementation of the Enigma machine of name K (Switzerland)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -30,29 +29,37 @@ public class Enigma_K_Swiss_Standard extends Enigma_K
{
public Enigma_K_Swiss_Standard()
{
super(90);
super();
machineType = "KS";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_I(0,0));
addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_II(0,0));
addAvailableRotor(new Rotor.Rotor_KSwiss_Standard_III(0,0));
addAvailableReflector(new Reflector.Reflector_K_G260());
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long t = reflector.getRingSetting();
t = addDigit(t, reflector.getRotation(), 26);
t = addDigit(t, rotor3.getRingSetting(),26);
t = addDigit(t, rotor3.getRotation(), 26);
t = addDigit(t, rotor2.getRingSetting(),26);
t = addDigit(t, rotor2.getRotation(), 26);
t = addDigit(t, rotor1.getRingSetting(), 26);
t = addDigit(t, rotor1.getRotation(), 26);
t = addDigit(t, rotor3.getNumber(), 10);
t = addDigit(t, rotor2.getNumber(), 10);
t = addDigit(t, rotor1.getNumber(), 10);
t = addDigit(t, 8, 20); //Machine #8
BigInteger s = BigInteger.valueOf(reflector.getRingSetting());
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor3.getRingSetting(),26);
s = addDigit(s, rotor3.getRotation(), 26);
s = addDigit(s, rotor2.getRingSetting(),26);
s = addDigit(s, rotor2.getRotation(), 26);
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 8, 20); //Machine #8
save = save+t;
return save;
return s.toString(16);
}
}

View file

@ -1,10 +1,8 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.sql.Ref;
import java.util.Random;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
@ -29,20 +27,34 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_M3 extends Enigma_I
{
protected static int machineTypeOffset = 20;
public Enigma_M3()
{
super();
machineType = "M3";
}
@Override
protected void establishAvailableParts()
{
addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
addAvailableRotor(new Rotor.Rotor_I(0, 0));
addAvailableRotor(new Rotor.Rotor_II(0,0));
addAvailableRotor(new Rotor.Rotor_III(0,0));
addAvailableRotor(new Rotor.Rotor_IV(0,0));
addAvailableRotor(new Rotor.Rotor_V(0,0));
addAvailableRotor(new Rotor.Rotor_VI(0,0));
addAvailableRotor(new Rotor.Rotor_VII(0,0));
addAvailableRotor(new Rotor.Rotor_VIII(0,0));
addAvailableReflector(new Reflector.Reflector_B());
addAvailableReflector(new Reflector.Reflector_C());
}
@Override
protected void generateState() {
int rotor1, rotor2=-1, rotor3=-1;
rotor1 = rand.nextInt(8);
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(8);
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(8);
int r1, r2=-1, r3=-1;
r1 = rand.nextInt(8);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(8);
while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(8);
int ref = rand.nextInt(2);
int rot1 = rand.nextInt(26);
@ -52,10 +64,11 @@ public class Enigma_M3 extends Enigma_I
int ring2 = rand.nextInt(26);
int ring3 = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + rotor1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + rotor2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + rotor3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset + ref);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(ref);
this.plugboard = new Plugboard();
plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
@ -63,20 +76,19 @@ public class Enigma_M3 extends Enigma_I
@Override
public String stateToString() {
String save = MainActivity.APP_ID+"/";
long s = rotor3.getRingSetting();
BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
s = addDigit(s, rotor3.getRingSetting(), 26);
s = addDigit(s, rotor3.getRotation(), 26);
s = addDigit(s, rotor2.getRingSetting(), 26);
s = addDigit(s, rotor2.getRotation(), 26);
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, reflector.getIndex(), availableReflectors.size());
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 1, 20); //Machine #1
save = save+s;
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
return save;
return s.toString(16);
}
}

View file

@ -1,14 +1,17 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.util.Random;
import android.util.Log;
import java.math.BigInteger;
import java.util.ArrayList;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Concrete Implementation of the Enigma Machine type M4 of the german Kriegsmarine
* Concrete Implementation of the Enigma Machine name M4 of the german Kriegsmarine
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -28,34 +31,73 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_M4 extends Enigma
{
private ArrayList<Rotor> availableThinRotors;
private EntryWheel entryWheel;
private Rotor rotor1;
private Rotor rotor2;
private Rotor rotor3;
private Rotor rotor4;
private Reflector reflector;
private Plugboard plugboard;
protected static int machineTypeOffset = 30;
public Enigma_M4()
{
super();
machineType = "M4";
}
protected void addAvailableThinRotor(Rotor r)
{
if(availableThinRotors == null) availableThinRotors = new ArrayList<>();
availableThinRotors.add(availableThinRotors.size(), r.setIndex(availableThinRotors.size()));
}
public Rotor getThinRotor(int index)
{
if(availableThinRotors == null || availableThinRotors.size() == 0) return null;
return availableThinRotors.get(index % availableThinRotors.size()).getInstance();
}
public Rotor getThinRotor(int index, int rotation, int ringSettings)
{
Rotor r = getThinRotor(index);
if(r == null) return null;
return r.setRotation(rotation).setRingSetting(ringSettings);
}
@Override
protected void establishAvailableParts()
{
Log.d(MainActivity.APP_ID, "Established");
addAvailableEntryWheel(new EntryWheel.EntryWheel_ABCDEF());
addAvailableRotor(new Rotor.Rotor_I(0, 0));
addAvailableRotor(new Rotor.Rotor_II(0,0));
addAvailableRotor(new Rotor.Rotor_III(0,0));
addAvailableRotor(new Rotor.Rotor_IV(0,0));
addAvailableRotor(new Rotor.Rotor_V(0,0));
addAvailableRotor(new Rotor.Rotor_VI(0,0));
addAvailableRotor(new Rotor.Rotor_VII(0, 0));
addAvailableRotor(new Rotor.Rotor_VIII(0,0));
addAvailableThinRotor(new Rotor.Rotor_M4_Beta(0, 0));
addAvailableThinRotor(new Rotor.Rotor_M4_Gamma(0, 0));
addAvailableReflector(new Reflector.Reflector_Thin_B());
addAvailableReflector(new Reflector.ReflectorThinC());
}
@Override
public void initialize()
{
Log.d(MainActivity.APP_ID, "Initialized");
this.plugboard = new Plugboard();
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, 0, 0);
this.rotor4 = Rotor.createRotor(machineTypeOffset + 8, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.prefAnomaly = ((MainActivity) MainActivity.ActivitySingleton.getInstance()
.getActivity()).getPrefAnomaly();
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0, 0, 0);
this.rotor2 = getRotor(1, 0, 0);
this.rotor3 = getRotor(2, 0, 0);
this.rotor4 = getThinRotor(0, 0, 0);
this.reflector = getReflector(0);
}
@Override
@ -69,7 +111,7 @@ public class Enigma_M4 extends Enigma
//Rotate rotors
rotor1.rotate();
//Eventually turn next rotor (usual turnOver or anomaly)
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
//Set doAnomaly for next call of encryptChar
@ -104,14 +146,13 @@ public class Enigma_M4 extends Enigma
int ring4 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.rotor4 = Rotor.createRotor(machineTypeOffset + 8 + r4, rot4, ring4);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.rotor4 = getThinRotor(r4, rot4, ring4);
this.reflector = Reflector.createReflector(machineTypeOffset + ref);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.reflector = getReflector(ref, rotRef, ringRef);
this.plugboard = new Plugboard();
this.plugboard.setConfiguration(Plugboard.seedToPlugboardConfiguration(rand));
@ -133,6 +174,7 @@ public class Enigma_M4 extends Enigma
//Encryption
//forward direction
x = plugboard.encrypt(x);
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());
@ -153,6 +195,7 @@ public class Enigma_M4 extends Enigma
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);
x = plugboard.encrypt(x);
return (char) (x + 65); //Add Offset again and cast back to char
}
@ -160,11 +203,11 @@ public class Enigma_M4 extends Enigma
@Override
public void setState(EnigmaStateBundle state)
{
rotor1 = Rotor.createRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
rotor2 = Rotor.createRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
rotor3 = Rotor.createRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
rotor4 = Rotor.createRotor(state.getTypeRotor4(), state.getRotationRotor4(), state.getRingSettingRotor4());
reflector = Reflector.createReflector(state.getTypeReflector());
rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
rotor4 = getThinRotor(state.getTypeRotor4(), state.getRotationRotor4(), state.getRingSettingRotor4());
reflector = getReflector(state.getTypeReflector());
plugboard.setConfiguration(state.getConfigurationPlugboard());
}
@ -173,10 +216,12 @@ public class Enigma_M4 extends Enigma
public EnigmaStateBundle getState()
{
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor4(rotor4.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setTypeRotor4(rotor4.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -188,7 +233,7 @@ public class Enigma_M4 extends Enigma
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setRingSettingRotor4(rotor4.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setConfigurationPlugboard(plugboard.getConfiguration());
@ -196,23 +241,18 @@ public class Enigma_M4 extends Enigma
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
String plugboardConf = mem.substring(mem.lastIndexOf(":p") + 2);
long s = Long.valueOf(mem.substring(0, mem.indexOf(":p")));
s = removeDigit(s, 20); //Remove machine type
int r1 = getValue(s, 10);
s = removeDigit(s, 10);
int r2 = getValue(s, 10);
s = removeDigit(s,10);
int r3 = getValue(s, 10);
s = removeDigit(s,10);
int r4 = getValue(s, 10);
s = removeDigit(s,10);
int ref = getValue(s, 10);
s = removeDigit(s,10);
int r1 = getValue(s, availableRotors.size());
s = removeDigit(s, availableRotors.size());
int r2 = getValue(s, availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r3 = getValue(s, availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r4 = getValue(s, availableThinRotors.size());
s = removeDigit(s,availableThinRotors.size());
int ref = getValue(s, availableReflectors.size());
s = removeDigit(s,availableReflectors.size());
int rot1 = getValue(s, 26);
s = removeDigit(s,26);
@ -233,23 +273,21 @@ public class Enigma_M4 extends Enigma
int rotRef = getValue(s, 26);
s = removeDigit(s,26);
int ringRef = getValue(s, 26);
s = removeDigit(s,26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.rotor4 = Rotor.createRotor(machineTypeOffset + r4, rot4, ring4);
this.reflector = Reflector.createReflector(machineTypeOffset + ref);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.rotor4 = getThinRotor(r4, rot4, ring4);
this.reflector = getReflector(ref, rotRef, ringRef);
this.plugboard = new Plugboard();
plugboard.setConfiguration(Plugboard.stringToConfiguration(plugboardConf));
plugboard.setConfiguration(s);
}
@Override
public String stateToString() {
String save = MainActivity.APP_ID+"/";
long s = reflector.getRingSetting();
BigInteger s = Plugboard.configurationToBigInteger(plugboard.getConfiguration());
s = addDigit(s, reflector.getRingSetting(), 26);
s = addDigit(s, reflector.getRotation(), 26);
s = addDigit(s, rotor4.getRingSetting(), 26);
s = addDigit(s, rotor4.getRotation(), 26);
@ -260,16 +298,13 @@ public class Enigma_M4 extends Enigma
s = addDigit(s, rotor1.getRingSetting(), 26);
s = addDigit(s, rotor1.getRotation(), 26);
s = addDigit(s, reflector.getNumber(), 10);
s = addDigit(s, rotor4.getNumber(), 10);
s = addDigit(s, rotor3.getNumber(), 10);
s = addDigit(s, rotor2.getNumber(), 10);
s = addDigit(s, rotor1.getNumber(), 10);
s = addDigit(s, reflector.getIndex(), availableReflectors.size());
s = addDigit(s, rotor4.getIndex(), availableThinRotors.size());
s = addDigit(s, rotor3.getIndex(), availableRotors.size());
s = addDigit(s, rotor2.getIndex(), availableRotors.size());
s = addDigit(s, rotor1.getIndex(), availableRotors.size());
s = addDigit(s, 2, 20);
save = save+s;
save = save + ":p" + Plugboard.configurationToString(getState().getConfigurationPlugboard());
return save;
return s.toString(16);
}
}

View file

@ -1,14 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import java.security.SecureRandom;
import java.util.Random;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type R ("Rocket", Reichsbahn)
* Implementation of the Enigma machine of name R ("Rocket", Reichsbahn)
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -28,35 +27,44 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_R extends Enigma
{
protected Rotor entryWheel;
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
protected static int machineTypeOffset = 110;
public Enigma_R()
{
super();
machineType = "R";
}
@Override
protected void establishAvailableParts() {
addAvailableEntryWheel(new EntryWheel.EntryWheel_QWERTZ());
addAvailableRotor(new Rotor.Rotor_R_I(0, 0));
addAvailableRotor(new Rotor.Rotor_R_II(0,0));
addAvailableRotor(new Rotor.Rotor_R_III(0,0));
addAvailableReflector(new Reflector.Reflector_R());
}
@Override
public void initialize()
{
this.entryWheel = Rotor.createRotor(1, 0, 0);
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0);
this.rotor2 = getRotor(1);
this.rotor3 = getRotor(2);
this.reflector = getReflector(0);
}
@Override
public void nextState()
{
rotor1.rotate();
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
this.doAnomaly = rotor2.doubleTurnAnomaly();
@ -70,10 +78,10 @@ public class Enigma_R extends Enigma
@Override
protected void generateState()
{
int rotor1, rotor2=-1, rotor3=-1;
rotor1 = rand.nextInt(3);
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(3);
rotor3 = 3 - rotor1 - rotor2;
int r1, r2=-1, r3;
r1 = rand.nextInt(3);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(3);
r3 = 3 - r1 - r2;
int rot1 = rand.nextInt(26);
int rot2 = rand.nextInt(26);
@ -84,12 +92,11 @@ public class Enigma_R extends Enigma
int ring3 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + rotor1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + rotor2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + rotor3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
reflector.setRotation(rotRef);
reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
@ -122,24 +129,22 @@ public class Enigma_R extends Enigma
@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());
this.entryWheel = getEntryWheel(state.getTypeEntryWheel());
this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
}
@Override
public EnigmaStateBundle getState() {
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeEntryWheel(entryWheel.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -149,7 +154,7 @@ public class Enigma_R extends Enigma
state.setRingSettingRotor2(rotor2.getRingSetting());
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setRotationReflector(reflector.getRotation());
state.setRingSettingReflector(reflector.getRingSetting());
@ -157,46 +162,43 @@ public class Enigma_R extends Enigma
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
long s = Long.valueOf(mem);
s = removeDigit(s,20); //Remove machine type
int r1 = getValue(s,10);
s = removeDigit(s,10);
int r2 = getValue(s,10);
s = removeDigit(s,10);
int r3 = getValue(s,10);
s = removeDigit(s,10);
int r1 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r2 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r3 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int rot1 = getValue(s,26);
s = removeDigit(s,26);
int ring1 = getValue(s,26);
s = removeDigit(s,26);
int rot2 = getValue(s,26);
s = removeDigit(s,26);
int ring2 = getValue(s,26);
s = removeDigit(s,26);
int rot3 = getValue(s,26);
s = removeDigit(s,26);
int ring3 = getValue(s,26);
s = removeDigit(s,26);
int rotRef = getValue(s,26);
s = removeDigit(s,26);
int ringRef = getValue(s,26);
int rot1 = getValue(s, 26);
s = removeDigit(s, 26);
int ring1 = getValue(s, 26);
s = removeDigit(s, 26);
int rot2 = getValue(s, 26);
s = removeDigit(s, 26);
int ring2 = getValue(s, 26);
s = removeDigit(s, 26);
int rot3 = getValue(s, 26);
s = removeDigit(s, 26);
int ring3 = getValue(s, 26);
s = removeDigit(s, 26);
int rotRef = getValue(s, 26);
s = removeDigit(s, 26);
int ringRef = getValue(s, 26);
s = removeDigit(s, 26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long t = reflector.getRingSetting();
BigInteger t = BigInteger.valueOf(reflector.getRingSetting());
t = addDigit(t, reflector.getRotation(), 26);
t = addDigit(t, rotor3.getRingSetting(),26);
t = addDigit(t, rotor3.getRotation(), 26);
@ -204,12 +206,11 @@ public class Enigma_R extends Enigma
t = addDigit(t, rotor2.getRotation(), 26);
t = addDigit(t, rotor1.getRingSetting(), 26);
t = addDigit(t, rotor1.getRotation(), 26);
t = addDigit(t, rotor3.getNumber(), 10);
t = addDigit(t, rotor2.getNumber(), 10);
t = addDigit(t, rotor1.getNumber(), 10);
t = addDigit(t, rotor3.getIndex(), availableRotors.size());
t = addDigit(t, rotor2.getIndex(), availableRotors.size());
t = addDigit(t, rotor1.getIndex(), availableRotors.size());
t = addDigit(t, 10, 20); //Machine #10
save = save+t;
return save;
return t.toString(16);
}
}

View file

@ -1,16 +1,13 @@
package de.vanitasvitae.enigmandroid.enigma;
import android.util.Log;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.rotors.EntryWheel;
import de.vanitasvitae.enigmandroid.enigma.rotors.Reflector;
import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
/**
* Implementation of the Enigma machine of type T Tirpitz
* Implementation of the Enigma machine of name T Tirpitz
* Copyright (C) 2015 Paul Schaub
This program is free software; you can redistribute it and/or modify
@ -30,34 +27,46 @@ import de.vanitasvitae.enigmandroid.enigma.rotors.Rotor;
*/
public class Enigma_T extends Enigma
{
protected Rotor entryWheel;
protected EntryWheel entryWheel;
protected Rotor rotor1;
protected Rotor rotor2;
protected Rotor rotor3;
protected Reflector reflector;
protected static int machineTypeOffset = 120;
public Enigma_T()
{
super();
machineType = "T";
}
@Override
protected void establishAvailableParts() {
addAvailableEntryWheel(new EntryWheel.EntryWheel_T());
addAvailableRotor(new Rotor.Rotor_T_I(0, 0));
addAvailableRotor(new Rotor.Rotor_T_II(0,0));
addAvailableRotor(new Rotor.Rotor_T_III(0,0));
addAvailableRotor(new Rotor.Rotor_T_IV(0,0));
addAvailableRotor(new Rotor.Rotor_T_V(0,0));
addAvailableRotor(new Rotor.Rotor_T_VI(0,0));
addAvailableRotor(new Rotor.Rotor_T_VII(0,0));
addAvailableRotor(new Rotor.Rotor_T_VIII(0,0));
addAvailableReflector(new Reflector.ReflectorEnigma_T());
}
@Override
public void initialize() {
this.entryWheel = Rotor.createRotor(2,0,0);
this.rotor1 = Rotor.createRotor(machineTypeOffset, 0, 0);
this.rotor2 = Rotor.createRotor(machineTypeOffset+1, 0, 0);
this.rotor3 = Rotor.createRotor(machineTypeOffset+2, 0, 0);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(0);
this.rotor2 = getRotor(1);
this.rotor3 = getRotor(2);
this.reflector = getReflector(0);
}
@Override
public void nextState()
{
rotor1.rotate();
if (rotor1.isAtTurnoverPosition() || (this.doAnomaly && prefAnomaly))
if (rotor1.isAtTurnoverPosition() || this.doAnomaly)
{
rotor2.rotate();
this.doAnomaly = rotor2.doubleTurnAnomaly();
@ -70,10 +79,10 @@ public class Enigma_T extends Enigma
@Override
protected void generateState() {
int rotor1, rotor2=-1, rotor3=-1;
rotor1 = rand.nextInt(8);
while(rotor2 == -1 || rotor2 == rotor1) rotor2 = rand.nextInt(8);
while(rotor3 == -1 || rotor3 == rotor2 || rotor3 == rotor1) rotor3 = rand.nextInt(8);
int r1, r2=-1, r3=-1;
r1 = rand.nextInt(8);
while(r2 == -1 || r2 == r1) r2 = rand.nextInt(8);
while(r3 == -1 || r3 == r2 || r3 == r1) r3 = rand.nextInt(8);
int rot1 = rand.nextInt(26);
int rot2 = rand.nextInt(26);
@ -84,12 +93,11 @@ public class Enigma_T extends Enigma
int ring3 = rand.nextInt(26);
int ringRef = rand.nextInt(26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + rotor1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + rotor2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + rotor3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
reflector.setRotation(rotRef);
reflector.setRingSetting(ringRef);
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
@ -121,13 +129,11 @@ public class Enigma_T extends Enigma
@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());
this.entryWheel = getEntryWheel(0);
this.rotor1 = getRotor(state.getTypeRotor1(), state.getRotationRotor1(), state.getRingSettingRotor1());
this.rotor2 = getRotor(state.getTypeRotor2(), state.getRotationRotor2(), state.getRingSettingRotor2());
this.rotor3 = getRotor(state.getTypeRotor3(), state.getRotationRotor3(), state.getRingSettingRotor3());
this.reflector = getReflector(state.getTypeReflector(), state.getRotationReflector(), state.getRingSettingReflector());
}
@Override
@ -135,9 +141,9 @@ public class Enigma_T extends Enigma
{
EnigmaStateBundle state = new EnigmaStateBundle();
state.setTypeRotor1(rotor1.getNumber());
state.setTypeRotor2(rotor2.getNumber());
state.setTypeRotor3(rotor3.getNumber());
state.setTypeRotor1(rotor1.getIndex());
state.setTypeRotor2(rotor2.getIndex());
state.setTypeRotor3(rotor3.getIndex());
state.setRotationRotor1(rotor1.getRotation());
state.setRotationRotor2(rotor2.getRotation());
@ -147,25 +153,23 @@ public class Enigma_T extends Enigma
state.setRingSettingRotor2(rotor2.getRingSetting());
state.setRingSettingRotor3(rotor3.getRingSetting());
state.setTypeReflector(reflector.getNumber());
state.setTypeReflector(reflector.getIndex());
state.setRotationReflector(reflector.getRotation());
state.setRingSettingReflector(reflector.getRingSetting());
state.setTypeEntryWheel(entryWheel.getNumber());
state.setTypeEntryWheel(entryWheel.getIndex());
return state;
}
@Override
public void restoreState(String mem)
public void restoreState(BigInteger s)
{
long s = Long.valueOf(mem);
s = removeDigit(s,20); //Remove machine type
int r1 = getValue(s,10);
s = removeDigit(s,10);
int r2 = getValue(s,10);
s = removeDigit(s,10);
int r3 = getValue(s,10);
s = removeDigit(s,10);
int r1 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r2 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int r3 = getValue(s,availableRotors.size());
s = removeDigit(s,availableRotors.size());
int rot1 = getValue(s,26);
s = removeDigit(s,26);
@ -183,19 +187,16 @@ public class Enigma_T extends Enigma
s = removeDigit(s,26);
int ringRef = getValue(s,26);
this.rotor1 = Rotor.createRotor(machineTypeOffset + r1, rot1, ring1);
this.rotor2 = Rotor.createRotor(machineTypeOffset + r2, rot2, ring2);
this.rotor3 = Rotor.createRotor(machineTypeOffset + r3, rot3, ring3);
this.reflector = Reflector.createReflector(machineTypeOffset);
this.reflector.setRotation(rotRef);
this.reflector.setRingSetting(ringRef);
this.rotor1 = getRotor(r1, rot1, ring1);
this.rotor2 = getRotor(r2, rot2, ring2);
this.rotor3 = getRotor(r3, rot3, ring3);
this.reflector = getReflector(0, rotRef, ringRef);
}
@Override
public String stateToString()
{
String save = MainActivity.APP_ID+"/";
long t = reflector.getRingSetting();
BigInteger t = BigInteger.valueOf(reflector.getRingSetting());
t = addDigit(t, reflector.getRotation(), 26);
t = addDigit(t, rotor3.getRingSetting(),26);
t = addDigit(t, rotor3.getRotation(), 26);
@ -203,12 +204,11 @@ public class Enigma_T extends Enigma
t = addDigit(t, rotor2.getRotation(), 26);
t = addDigit(t, rotor1.getRingSetting(), 26);
t = addDigit(t, rotor1.getRotation(), 26);
t = addDigit(t, rotor3.getNumber(), 10);
t = addDigit(t, rotor2.getNumber(), 10);
t = addDigit(t, rotor1.getNumber(), 10);
t = addDigit(t, rotor3.getIndex(), availableRotors.size());
t = addDigit(t, rotor2.getIndex(), availableRotors.size());
t = addDigit(t, rotor1.getIndex(), availableRotors.size());
t = addDigit(t, 11, 20); //Machine #11
save = save+t;
return save;
return t.toString(16);
}
}

View file

@ -1,7 +1,12 @@
package de.vanitasvitae.enigmandroid.enigma;
import android.util.Log;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Random;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
/**
@ -25,7 +30,7 @@ import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
*/
public class Plugboard
{
public static final int[] empty = {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};
private static final int[] empty = {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};
private int[] plugs;
public Plugboard()
@ -43,6 +48,21 @@ public class Plugboard
this.plugs = conf;
}
public BigInteger setConfiguration(BigInteger b)
{
String s = "";
int x;
while((x = Enigma.getValue(b, 27)) != 26 || b.compareTo(BigInteger.ZERO) > 1)
{
s = ((char) (x+65))+s;
b = Enigma.removeDigit(b, 27);
}
Log.d(MainActivity.APP_ID, "Restored: " + s);
this.setConfiguration(stringToConfiguration(s));
return b;
}
public int[] getConfiguration()
{
return this.plugs;
@ -70,7 +90,8 @@ public class Plugboard
String pairs = trimString(new InputPreparer.RemoveIllegalCharacters().prepareString(in));
int[] out = empty;
//Check if in is too long or odd
if(pairs.length() > 26 || pairs.length()/2 == (pairs.length()-1)/2)
int l = pairs.length();
if(l>1 && (pairs.length() > 26 || pairs.length()/2 == (pairs.length()-1)/2))
{
//Odd length. remove last char. Information loss!
pairs = pairs.substring(0,pairs.length()-1);
@ -137,13 +158,12 @@ public class Plugboard
*/
public static int[] seedToReflectorConfiguration(Random rand)
{
int[] out = empty;
for(int i=0; i<empty.length; i++)
{
int[] out = Arrays.copyOf(empty,empty.length);
for (int i=0; i<out.length/2; i++) {
int rA = rand.nextInt(26);
while(out[rA] != rA) rA = (rA+1)%26;
while (out[rA] != rA) rA = (rA + 27) % 26;
int rB = rand.nextInt(26);
while(out[rB] != rB) rB = (rB+1)%26;
while (out[rB] != rB || rA == rB) rB = (rB + 27) % 26;
out[rA] = rB;
out[rB] = rA;
}
@ -169,16 +189,32 @@ public class Plugboard
return out;
}
public static long configurationToLong(int[] a)
public static BigInteger configurationToBigInteger(int[] a)
{
String s = configurationToString(a);
long l = 0;
BigInteger l = BigInteger.ZERO;
l = Enigma.addDigit(l,26,27);
for(char c : s.toCharArray())
{
int i = (int) (c);
i-=65;
Enigma.addDigit(l,i,26);
l = Enigma.addDigit(l,i,27);
}
Log.d(MainActivity.APP_ID, "Save configuration plugs: "+l.toString());
return l;
}
public static int[] bigIntegerToConfiguration(BigInteger b)
{
String s = "";
int x;
while((x = Enigma.getValue(b, 27)) != 26 || b.compareTo(BigInteger.ZERO) > 1)
{
s = ((char) (x+65))+s;
b = Enigma.removeDigit(b, 27);
}
Log.d(MainActivity.APP_ID, "Restored: "+s);
return stringToConfiguration(s);
}
}

View file

@ -79,11 +79,11 @@ public abstract class EditTextAdapter
public static class EditTextAdapterGap extends EditTextAdapter
{
protected int blocksize;
public EditTextAdapterGap(EditText editText, int blocksize)
protected int blockSize;
public EditTextAdapterGap(EditText editText, int blockSize)
{
super(editText);
this.blocksize = blocksize;
this.blockSize = blockSize;
}
@Override
@ -92,12 +92,12 @@ public abstract class EditTextAdapter
this.content = text;
String out = "";
int i;
for(i=0; i<text.length()/blocksize; i++)
for(i=0; i<text.length()/blockSize; i++)
{
out = out + text.substring(i*blocksize, (i+1)*blocksize);
out = out + text.substring(i*blockSize, (i+1)*blockSize);
out = out + " ";
}
out = out + text.substring(i*blocksize);
out = out + text.substring(i*blockSize);
this.editText.setText(out);
}
}

View file

@ -46,7 +46,6 @@ public abstract class InputPreparer {
boolean replaceSpecialChars = sharedPreferences.getBoolean(SettingsActivity.PREF_REPLACE_SPECIAL_CHARACTERS, true);
String num_lang = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, main.getResources().
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
boolean replaceSpaces = sharedPreferences.getBoolean(SettingsActivity.PREF_REPLACE_SPACES, false);
InputPreparer inPrep = new RemoveIllegalCharacters();
if(replaceSpecialChars) inPrep = new ReplaceSpecialCharacters(inPrep);
switch (num_lang)
@ -162,7 +161,7 @@ public abstract class InputPreparer {
/**
* "Final Stage" of Input preparing. This should always be called last
* (choose this as the inner most capsule of InputPreparers)
* This cant have child Inputpreparers.
* This cant have child InputPreparers.
* This Input preparer removes all characters from the string besides A..Z
*/
public static class RemoveIllegalCharacters extends InputPreparer

View file

@ -0,0 +1,135 @@
package de.vanitasvitae.enigmandroid.enigma.rotors;
/**
* Implementation of several EntryWheels
* 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 EntryWheel
{
protected int type;
protected String name;
protected int index;
protected String summary;
protected Integer[] connections;
protected Integer[] reversedConnections;
public EntryWheel(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections)
{
this.type = type;
this.name = name;
this.summary = summary;
this.connections = connections;
this.reversedConnections = reversedConnections;
}
/**
* Returns a new EntryWheel of the same type as the callee
* @return new EntryWheel
*/
public EntryWheel getInstance()
{
return createEntryWheel(this.type).setIndex(this.getIndex());
}
/**
* Encrypt an input signal via the internal wiring in "forward" direction towards the reflector
* (using connections)
* @param input signal
* @return encrypted signal
*/
public int encryptForward(int input)
{
return this.connections[normalize(input)];
}
public int normalize(int input)
{
return (input+this.connections.length)%this.connections.length;
}
public EntryWheel setIndex(int index)
{
this.index = index;
return this;
}
public int getIndex()
{
return this.index;
}
/**
* Encrypt an input signal via the internal wiring in "backwards" direction (using
* reversedConnections)
* @param input signal
* @return encrypted signal
*/
public int encryptBackward(int input)
{
return this.reversedConnections[normalize(input)];
}
public EntryWheel createEntryWheel(int type)
{
switch(type)
{
case 1:
return new EntryWheel_QWERTZ();
case 2:
return new EntryWheel_T();
default: return new EntryWheel_ABCDEF();
}
}
public static class EntryWheel_ABCDEF extends EntryWheel
{
public EntryWheel_ABCDEF()
{
super(0, "ABCDEF", "abcdefghijklmnopqrstuvwxyz",
new Integer[]{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},
new Integer[]{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});
}
}
/**
* EntryWheel as used in the Enigma models D, K, G
* 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
*/
public static class EntryWheel_QWERTZ extends EntryWheel
{
public EntryWheel_QWERTZ()
{
super(1, "QWERTZ", "qwertzuioasdfghjkpyxcvbnml",
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},
new Integer[]{16,22,4,17,19,25,20,8,14,0,18,3,5,6,7,9,10,15,24,23,2,21,1,13,12,11});
}
}
/**
* EntryWheel as used only in the Enigma Type T Tirpitz
* K Z R O U Q H Y A I G B L W V S T D X F P N M C J E
*/
public static class EntryWheel_T extends EntryWheel
{
public EntryWheel_T()
{
super(2, "KZROUQ", "kzrouqhyaigblwvstdxfpnmcje",
new Integer[]{8,11,23,17,25,19,10,6,9,24,0,12,22,21,3,20,5,2,15,16,4,14,13,18,7,1},
new Integer[]{10,25,17,14,20,16,7,24,0,8,6,1,11,22,21,18,19,3,23,5,15,13,12,2,9,4});
}
}
}

View file

@ -2,10 +2,11 @@ package de.vanitasvitae.enigmandroid.enigma.rotors;
import android.util.Log;
import java.util.Random;
import java.math.BigInteger;
import de.vanitasvitae.enigmandroid.MainActivity;
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
import de.vanitasvitae.enigmandroid.enigma.Enigma;
import de.vanitasvitae.enigmandroid.enigma.Plugboard;
/**
* Reflector of the enigma machine.
@ -30,27 +31,53 @@ import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
*/
public class Reflector
{
protected String type;
protected int number;
protected int type;
protected String name;
protected int index;
protected String summary;
protected int[] connections;
protected int rotation;
protected int ringSetting;
public static final int[] defaultWiring_D_KD_G31 = {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};
/**
* This constructor is not accessible from outside this class file.
* Use the one of the createReflector* methods instead to create concrete Reflectors from
* outside this class file
* @param type type indicator of the reflector
* @param type name indicator of the reflector
* @param connections wiring of the reflector as Integer array
*/
protected Reflector(String type, int[] connections)
protected Reflector(int type, String name, String summary, int[] connections)
{
this.type = type;
this.name = name;
this.summary = summary;
this.connections = connections;
}
public Reflector getInstance()
{
//noinspection ConstantConditions
return createReflector(this.type).setIndex(this.getIndex());
}
public Reflector getInstance(int rotation, int ringSetting)
{
//noinspection ConstantConditions
return createReflector(this.type).setIndex(this.getIndex())
.setRotation(rotation).setRingSetting(ringSetting);
}
public Reflector setIndex(int index)
{
this.index = index;
return this;
}
public int getIndex()
{
return this.index;
}
public int getRotation()
{
return rotation;
@ -61,19 +88,37 @@ public class Reflector
return ringSetting;
}
public void setRotation(int rotation)
public Reflector setRotation(int rotation)
{
this.rotation = rotation;
return this;
}
public void setRingSetting(int ringSetting)
public Reflector setRingSetting(int ringSetting)
{
this.ringSetting = ringSetting;
return this;
}
public void setConfiguration(int[] c)
public Reflector setConfiguration(int[] c)
{
this.connections = c;
return this;
}
public BigInteger setConfiguration(BigInteger b)
{
String s = "";
int x;
while((x = Enigma.getValue(b, 27)) != 26 || b.compareTo(BigInteger.ZERO) > 1)
{
s = ((char) (x+65))+s;
b = Enigma.removeDigit(b, 27);
}
Log.d(MainActivity.APP_ID, "Restored: " + s);
this.setConfiguration(Plugboard.stringToConfiguration(s));
return b;
}
public int[] getConfiguration()
@ -83,7 +128,7 @@ public class Reflector
/**
* Factory method to create reflectors.
* @param type type of the created reflector
* @param type name of the created reflector
* 1 -> ReflectorA
* 2 -> ReflectorB
* 3 -> ReflectorC
@ -100,61 +145,25 @@ public class Reflector
*/
public static Reflector createReflector(int type)
{
Log.d(MainActivity.APP_ID, "Reflectorcreation: "+type);
switch (type)
{
//Enigma I
case 10: return new ReflectorA().setNumber(type);
case 11: return new ReflectorB().setNumber(type);
case 12: return new ReflectorC().setNumber(type);
//Enigma M3
case 20: return new ReflectorB().setNumber(type);
case 21: return new ReflectorC().setNumber(type);
//Enigma M4
case 30: return new ReflectorThinB().setNumber(type);
case 31: return new ReflectorThinC().setNumber(type);
//Enigma G31
case 40: return new ReflectorEnigma_D_KD_G31().setNumber(type);
//Enigma G312
case 50: return new Reflector_G312().setNumber(type);
//Enigma G260
case 60: return new Reflector_G260().setNumber(type);
//Enigma D
case 70: return new ReflectorEnigma_D_KD_G31().setNumber(type);
//Enigma K
case 80: return new ReflectorEnigma_K().setNumber(type);
//Enigma K Swiss
case 90: return new ReflectorEnigma_K().setNumber(type);
//Enigma K Swiss Airforce
case 100: return new ReflectorEnigma_K().setNumber(type);
//Enigma R
case 110: return new Reflector_R().setNumber(type);
//Enigma T
case 120: return new ReflectorEnigma_T().setNumber(type);
case 0: return new Reflector_A();
case 1: return new Reflector_B();
case 2: return new Reflector_C();
case 10: return new Reflector_Thin_B();
case 11: return new ReflectorThinC();
case 20: return new ReflectorEnigma_D_KD_G31();
case 30: return new Reflector_G312();
case 40: return new Reflector_K_G260();
case 50: return new Reflector_R();
case 60: return new ReflectorEnigma_T();
default:
Log.e(MainActivity.APP_ID," Tried to create Reflector of invalid type "+type);
Log.e(MainActivity.APP_ID," Tried to create Reflector of invalid name "+type);
return null;
}
}
public Reflector setNumber(int nr)
{
this.number = nr;
return this;
}
/**
* Substitute an input signal via the wiring of the reflector with a different (!) output.
* The output MUST not be equal to the input for any input, since this was not possible
@ -167,20 +176,6 @@ public class Reflector
return this.connections[normalize(input)];
}
/**
* Return the type indicator of the reflector
* @return type
*/
public String getType()
{
return this.type;
}
public int getNumber()
{
return this.number;
}
/**
* Return the size (ie the number of wires/length of the connections array) of the reflector
* @return size
@ -208,11 +203,12 @@ public class Reflector
* Used in Enigma I
* AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
*/
private static class ReflectorA extends Reflector
public static class Reflector_A extends Reflector
{
public ReflectorA()
public Reflector_A()
{
super("A", new int[]{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});
super(0, "A", "EJMZALYXVBWFCRQUONTSPIKHGD",
new int[]{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});
}
}
@ -221,11 +217,12 @@ public class Reflector
* Used in Enigma I, M3
* AY BR CU DH EQ FS GL IP JX KN MO TZ VW
*/
private static class ReflectorB extends Reflector
public static class Reflector_B extends Reflector
{
public ReflectorB()
public Reflector_B()
{
super("B", new int[]{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});
super(1, "B", "YRUHQSLDPXNGOKMIEBFZCWVJAT",
new int[]{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});
}
}
@ -234,112 +231,110 @@ public class Reflector
* Used in Enigma I, M3
* AF BV CP DJ EI GO HY KR LZ MX NW QT SU
*/
private static class ReflectorC extends Reflector
public static class Reflector_C extends Reflector
{
public ReflectorC()
public Reflector_C()
{
super("C", new int[]{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});
super(2, "C", "FVPJIAOYEDRZXWGCTKUGSBNMHL",
new int[]{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});
}
}
/**
* Concrete implementation of thin reflector type b (not equal to normal type b!)
* Concrete implementation of thin reflector name b (not equal to normal name b!)
* When used with Rotor Beta on rotation 0, the pair was equivalent to normal reflector B
* S->Beta->ThinB->Beta'->X == X->UKWB->S
* Used in Enigma M4
* E N K Q A U Y W J I C O P B L M D X Z V F T H R G S
*/
private static class ReflectorThinB extends Reflector
public static class Reflector_Thin_B extends Reflector
{
public ReflectorThinB()
public Reflector_Thin_B()
{
super("ThinB", new int[]{4,13,10,16,0,20,24,22,9,8,2,14,15,1,11,12,3,23,25,21,5,19,7,17,6,18});
super(10, "Thin-B", "ENKQAUYWJICOPBLMDXZVFTHRGS",
new int[]{4,13,10,16,0,20,24,22,9,8,2,14,15,1,11,12,3,23,25,21,5,19,7,17,6,18});
}
}
/**
* Concrete implementation of thin reflector type c (not equal to normal type c!)
* Concrete implementation of thin reflector name c (not equal to normal name c!)
* When used with Rotor Gamma on rotation 0, the pair was equivalent to normal reflector C
* S->Gamma->ThinC->Gamma'->X == X->UKWC->S
* Used in Enigma M4
* R D O B J N T K V E H M L F C W Z A X G Y I P S U Q
*/
private static class ReflectorThinC extends Reflector
public static class ReflectorThinC extends Reflector
{
public ReflectorThinC()
{
super("ThinC", new int[]{17,3,14,1,9,13,19,10,21,4,7,12,11,5,2,22,25,0,23,6,24,8,15,18,20,16});
super(11, "ThinC", "RDOBJNTKVEHMLFCWZAXGYIPSUQ",
new int[]{17,3,14,1,9,13,19,10,21,4,7,12,11,5,2,22,25,0,23,6,24,8,15,18,20,16});
}
}
/**
* Pluggable Reflector of the Enigma machine of type D and KD
* Pluggable Reflector of the Enigma machine of name 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 ReflectorEnigma_D_KD_G31 extends Reflector
{
public static final int[] defaultWiring_D_KD_G31 = {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};
public ReflectorEnigma_D_KD_G31()
{
super("Ref-D", defaultWiring_D_KD_G31);
super(20, "Ref-D", "Default: IMETCGFRAYSQBZXWLHKDVUPOJN", defaultWiring_D_KD_G31);
}
}
/**
* Reflector as used in various Enigma models of the K-Series
* I M E T C G F R A Y S Q B Z X W L H K D V U P O J N
*/
private static class ReflectorEnigma_K extends Reflector
{
public ReflectorEnigma_K()
{
super("Ref-K", new int[]{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 ReflectorEnigma_T extends Reflector
{
public ReflectorEnigma_T()
{
super("Ref-T", new int[]{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});
}
}
/**
* Reflector as used in the Enigma type G-312 Abwehr
* Reflector as used in the Enigma name G-312 Abwehr
* R U L Q M Z J S Y G O C E T K W D A H N B X P V I F
*/
private static class Reflector_G312 extends Reflector
public static class Reflector_G312 extends Reflector
{
public Reflector_G312()
{
super("Ref-G312", new int[]{17,20,11,16,12,25,9,18,24,6,14,2,4,19,10,22,3,0,7,13,1,23,15,21,8,5});
super(30, "Ref-G312", "RULQMZJSYGOCETKWDAHNBXPVIF",
new int[]{17,20,11,16,12,25,9,18,24,6,14,2,4,19,10,22,3,0,7,13,1,23,15,21,8,5});
}
}
/**
* Reflector as used in the Enigma type G-260 Abwehr
* Reflector as used in the Enigma name G-260 Abwehr
* I M E T C G F R A Y S Q B Z X W L H K D V U P O J N
*/
private static class Reflector_G260 extends Reflector
public static class Reflector_K_G260 extends Reflector
{
public Reflector_G260()
public Reflector_K_G260()
{
super("Ref-G260", new int[]{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});
super(40,"Ref-K/G260", "IMETCGFRAYSQBZXWLHKDVUPOJN",
new int[]{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 R "Rocket" (Reichsbahn)
* Q Y H O G N E C V P U Z T F D J A X W M K J S R B L
*/
private static class Reflector_R extends Reflector
public static class Reflector_R extends Reflector
{
public Reflector_R()
{
super("Ref-R", new int[]{16,24,7,14,6,13,4,2,21,15,20,25,19,5,3,9,0,23,22,12,10,8,18,17,1,11});
super(50, "Ref-R", "QYHOGNECVPUZTFDJAXWMKJSRBL",
new int[]{16,24,7,14,6,13,4,2,21,15,20,25,19,5,3,9,0,23,22,12,10,8,18,17,1,11});
}
}
/**
* Reflector as used in the Enigma name 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
*/
public static class ReflectorEnigma_T extends Reflector
{
public ReflectorEnigma_T()
{
super(60, "Ref-T", "GEKPBTAUMOCNILJDXZYFHWVQSR",
new int[]{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});
}
}
}

View file

@ -1,7 +1,6 @@
package de.vanitasvitae.enigmandroid.layout;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

View file

@ -1,11 +1,5 @@
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_G260;
/**
@ -30,11 +24,9 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_G260;
*/
public class LayoutContainer_G260 extends LayoutContainer_G31
{
protected static int offsetRot = 60;
public LayoutContainer_G260()
{
super(60);
super();
main.setTitle("G260 - EnigmAndroid");
this.resetLayout();
}

View file

@ -1,6 +1,5 @@
package de.vanitasvitae.enigmandroid.layout;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import de.vanitasvitae.enigmandroid.R;
@ -32,8 +31,6 @@ public class LayoutContainer_G31 extends LayoutContainer
{
protected Enigma enigma;
protected int offsetRot = 40;
protected Spinner rotor1View;
protected Spinner rotor2View;
protected Spinner rotor3View;
@ -43,12 +40,6 @@ public class LayoutContainer_G31 extends LayoutContainer
protected Spinner rotor3PositionView;
protected Spinner reflectorPositionView;
public LayoutContainer_G31(int off)
{
super();
this.offsetRot = off;
}
public LayoutContainer_G31()
{
super();
@ -94,9 +85,9 @@ public class LayoutContainer_G31 extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - offsetRot);
this.rotor2View.setSelection(state.getTypeRotor2() - offsetRot);
this.rotor3View.setSelection(state.getTypeRotor3() - offsetRot);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -107,9 +98,9 @@ public class LayoutContainer_G31 extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + offsetRot);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + offsetRot);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + offsetRot);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,11 +1,5 @@
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_G312;
/**
@ -32,7 +26,7 @@ public class LayoutContainer_G312 extends LayoutContainer_G31
{
public LayoutContainer_G312()
{
super(50);
super();
main.setTitle("G312 - EnigmAndroid");
this.resetLayout();
}

View file

@ -1,7 +1,6 @@
package de.vanitasvitae.enigmandroid.layout;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
@ -90,10 +89,10 @@ public class LayoutContainer_I extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 10);
this.rotor2View.setSelection(state.getTypeRotor2() - 10);
this.rotor3View.setSelection(state.getTypeRotor3() - 10);
this.reflectorView.setSelection(state.getTypeReflector() - 10);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.reflectorView.setSelection(state.getTypeReflector());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -103,10 +102,10 @@ public class LayoutContainer_I extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 10);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 10);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 10);
state.setTypeReflector(reflectorView.getSelectedItemPosition() + 10);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setTypeReflector(reflectorView.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,13 +1,11 @@
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;
import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard;
/**
* LayoutContainer for the Enigma Model K
@ -88,9 +86,9 @@ public class LayoutContainer_K extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 80);
this.rotor2View.setSelection(state.getTypeRotor2() - 80);
this.rotor3View.setSelection(state.getTypeRotor3() - 80);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -101,9 +99,9 @@ public class LayoutContainer_K extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 80);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 80);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 80);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,12 +1,10 @@
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;
import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard;
/**
@ -88,9 +86,9 @@ public class LayoutContainer_K_Swiss extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 90);
this.rotor2View.setSelection(state.getTypeRotor2() - 90);
this.rotor3View.setSelection(state.getTypeRotor3() - 90);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -101,9 +99,9 @@ public class LayoutContainer_K_Swiss extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 90);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 90);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 90);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,12 +1,10 @@
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;
import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Airforce;
/**
@ -88,9 +86,9 @@ public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 100);
this.rotor2View.setSelection(state.getTypeRotor2() - 100);
this.rotor3View.setSelection(state.getTypeRotor3() - 100);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -101,9 +99,9 @@ public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 100);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 100);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 100);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,7 +1,6 @@
package de.vanitasvitae.enigmandroid.layout;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
@ -82,10 +81,10 @@ public class LayoutContainer_M3 extends LayoutContainer_I
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 20);
this.rotor2View.setSelection(state.getTypeRotor2() - 20);
this.rotor3View.setSelection(state.getTypeRotor3() - 20);
this.reflectorView.setSelection(state.getTypeReflector() - 20);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.reflectorView.setSelection(state.getTypeReflector());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -95,10 +94,10 @@ public class LayoutContainer_M3 extends LayoutContainer_I
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 20);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 20);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 20);
state.setTypeReflector(reflectorView.getSelectedItemPosition() + 20);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setTypeReflector(reflectorView.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,7 +1,6 @@
package de.vanitasvitae.enigmandroid.layout;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
@ -100,11 +99,11 @@ public class LayoutContainer_M4 extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state) {
this.rotor1View.setSelection(state.getTypeRotor1() - 30);
this.rotor2View.setSelection(state.getTypeRotor2() - 30);
this.rotor3View.setSelection(state.getTypeRotor3() - 30);
this.rotor4View.setSelection(state.getTypeRotor4() - 38);
this.reflectorView.setSelection(state.getTypeReflector() - 30);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor4View.setSelection(state.getTypeRotor4());
this.reflectorView.setSelection(state.getTypeReflector());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -114,11 +113,11 @@ public class LayoutContainer_M4 extends LayoutContainer
@Override
public void syncStateFromLayoutToEnigma() {
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 30);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 30);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 30);
state.setTypeRotor4(rotor4View.getSelectedItemPosition() + 38);
state.setTypeReflector(reflectorView.getSelectedItemPosition() + 30);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setTypeRotor4(rotor4View.getSelectedItemPosition());
state.setTypeReflector(reflectorView.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -1,6 +1,5 @@
package de.vanitasvitae.enigmandroid.layout;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import de.vanitasvitae.enigmandroid.R;
@ -86,9 +85,9 @@ public class LayoutContainer_R extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 110);
this.rotor2View.setSelection(state.getTypeRotor2() - 110);
this.rotor3View.setSelection(state.getTypeRotor3() - 110);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
this.rotor3PositionView.setSelection(state.getRotationRotor3());
@ -99,9 +98,9 @@ public class LayoutContainer_R extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 110);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 110);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 110);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -85,9 +85,9 @@ public class LayoutContainer_T extends LayoutContainer
@Override
public void setLayoutState(EnigmaStateBundle state)
{
this.rotor1View.setSelection(state.getTypeRotor1() - 120);
this.rotor2View.setSelection(state.getTypeRotor2() - 120);
this.rotor3View.setSelection(state.getTypeRotor3() - 120);
this.rotor1View.setSelection(state.getTypeRotor1());
this.rotor2View.setSelection(state.getTypeRotor2());
this.rotor3View.setSelection(state.getTypeRotor3());
this.rotor1PositionView.setSelection(state.getRotationRotor1());
this.rotor2PositionView.setSelection(state.getRotationRotor2());
@ -99,9 +99,9 @@ public class LayoutContainer_T extends LayoutContainer
public void syncStateFromLayoutToEnigma()
{
EnigmaStateBundle state = getEnigma().getState();
state.setTypeRotor1(rotor1View.getSelectedItemPosition() + 120);
state.setTypeRotor2(rotor2View.getSelectedItemPosition() + 120);
state.setTypeRotor3(rotor3View.getSelectedItemPosition() + 120);
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());

View file

@ -35,10 +35,10 @@ import de.vanitasvitae.enigmandroid.R;
*/
public class PassphraseDialogBuilder
{
MainActivity main;
View passphraseDialogView;
EditText passphrase;
Button positive;
private MainActivity main;
private View passphraseDialogView;
private EditText passphrase;
private Button positive;
public PassphraseDialogBuilder()
{
main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();

View file

@ -314,7 +314,7 @@ public class PluggableDialogBuilder
/**
* Set buttons to not connected. That includes changing background to grey, set connection to
* itself.
* @param b
* @param b index of button
*/
private void setButtonFree(int b)
{

View file

@ -112,7 +112,8 @@ public abstract class RingSettingsDialogBuilder
{
if(adapters.length != 3 || rIDs.length != 3)
{
Log.d("Enigm|RingSettings", "Length of adapters array or length of rIDs array not equal to 3!");
Log.e(MainActivity.APP_ID, "RingSettingsDialogBuilderRotRotRot.showDialog():" +
" Length of adapters array or length of rIDs array not equal to 3!");
}
final Actions3 action = (Actions3) actions;
final MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
@ -232,7 +233,8 @@ public abstract class RingSettingsDialogBuilder
protected void showDialog(final EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions) {
if(adapters.length != 4 || rIDs.length != 4)
{
Log.d("Enigm|RingSettings", "Length of adapters array or length of rIDs array not equal to 4!");
Log.d(MainActivity.APP_ID, "RingSettingsDialogBuilderRotRotRotRef.showDialog():" +
"Length of adapters array or length of rIDs array not equal to 4!");
}
final Actions4 action = (Actions4) actions;
final MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();

View file

@ -1,5 +1,6 @@
<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="wrap_content"
android:paddingStart="5dp"
@ -17,63 +18,72 @@
android:layout_weight="2"
android:id="@+id/Q"
android:text="Q: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/W"
android:text="W: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/E"
android:text="E: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/R"
android:text="R: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/T"
android:text="T: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/Z"
android:text="Z: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/U"
android:text="U: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/I"
android:text="I: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/O"
android:text="O: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
</LinearLayout>
@ -94,56 +104,64 @@
android:layout_weight="2"
android:id="@+id/A"
android:text="A: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/S"
android:text="S: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/D"
android:text="D: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/F"
android:text="F: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/G"
android:text="G: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/H"
android:text="H: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/J"
android:text="J: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/K"
android:text="K: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Space
android:layout_width="0dp"
android:layout_weight="1"
@ -164,63 +182,72 @@
android:layout_weight="2"
android:id="@+id/P"
android:text="P: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/Y"
android:text="Y: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/X"
android:text="X: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/C"
android:text="C: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/V"
android:text="V: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/B"
android:text="B: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/N"
android:text="N: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/M"
android:text="M: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/L"
android:text="L: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
</LinearLayout>

View file

@ -12,7 +12,6 @@
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

View file

@ -41,7 +41,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Holo.Small"
android:text="@string/version"
android:id="@+id/about_version_section"/>
<!-- About How To -->

View file

@ -1,17 +1,12 @@
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="5dp"
android:paddingEnd="5dp">
<LinearLayout
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_passphrase"
android:id="@+id/passphrase"/>
</LinearLayout>
</RelativeLayout>
android:layout_height="wrap_content"
android:hint="@string/hint_passphrase"
android:id="@+id/passphrase"/>
</LinearLayout>

View file

@ -1,5 +1,6 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="5dp"
@ -17,35 +18,40 @@
android:layout_weight="2"
android:id="@+id/Q"
android:text="Q: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/W"
android:text="W: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/E"
android:text="E: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/R"
android:text="R: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/T"
android:text="T: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
@ -65,28 +71,32 @@
android:layout_weight="2"
android:id="@+id/Z"
android:text="Z: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/U"
android:text="U: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/I"
android:text="I: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/O"
android:text="O: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Space
android:layout_width="0dp"
android:layout_weight="1"
@ -107,35 +117,40 @@
android:layout_weight="2"
android:id="@+id/A"
android:text="A: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/S"
android:text="S: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/D"
android:text="D: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/F"
android:text="F: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/G"
android:text="G: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
</LinearLayout>
@ -156,28 +171,32 @@
android:layout_weight="2"
android:id="@+id/H"
android:text="H: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/J"
android:text="J: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/K"
android:text="K: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/P"
android:text="P: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Space
android:layout_width="0dp"
android:layout_weight="1"
@ -198,35 +217,40 @@
android:layout_weight="2"
android:id="@+id/Y"
android:text="Y: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/X"
android:text="X: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/C"
android:text="C: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/V"
android:text="V: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/B"
android:text="B: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
</LinearLayout>
@ -247,21 +271,24 @@
android:layout_weight="2"
android:id="@+id/N"
android:text="N: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/M"
android:text="M: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/L"
android:text="L: "
android:background="@drawable/button_grey"/>
android:background="@drawable/button_grey"
tools:ignore="HardcodedText" />
<Space
android:layout_width="0dp"
android:layout_weight="2"

View file

@ -12,10 +12,8 @@
<string name="action_choose_ringsettings">Ringstellung</string>
<string name="action_send">Senden</string>
<string name="send_to">Senden an…</string>
<string name="message_choose_ringsettings">Wähle die Ringstellungen für die Walzen:</string>
<string name="hint_enigma_type_here">Hier Tippen</string>
<string name="hint_enigma_code">Enigma-Code</string>
<string name="hint_enigma_plugboard">Steckerbrett (AZ,BE…)</string>
<string name="hint_rotor1">Walze 1</string>
<string name="hint_rotor2">Walze 2</string>
<string name="hint_rotor3">Walze 3</string>
@ -29,9 +27,6 @@
<string name="hint_enigma_reflector_wiring">Verkabelung Umkehrwalze</string>
<string name="hint_passphrase">Schlüsselwort eingeben</string>
<string name="button_crypt">Ver-/Entschlüsseln</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_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_valid_qr">Fehler: Kein korrekter EnigmAndroid QR-Code!</string>
<string name="title_ringsetting">Ringstellungen</string>
@ -39,7 +34,6 @@
<string name="title_reflector_dialog">Verkabelung Umkehrwalze</string>
<string name="dialog_positiv">OK</string>
<string name="dialog_negativ">Abbrechen</string>
<string name="dialog_clear">Löschen</string>
<string name="dialog_ringsettings_success">Setze Ringe auf</string>
<string name="dialog_reflector_set">Umkehrwalze verkabelt.</string>
<string name="dialog_plugboard_set">Steckbrett gesteckert.</string>

View file

@ -17,14 +17,8 @@
<item>R (\"Rocket\", Reichsbahn)</item>
<item>T (\"Tirpitz\", Japan)</item>
</string-array>
<string name="pref_title_simulate_anomaly">Doppelschritt Anomalie</string>
<string name="pref_description_simulate_anomaly">Die Doppelschritt Anomalie lässt die mittlere Walze zweimal rotieren,
falls sie sich vor dem Übertragspunkt befindet.</string>
<string name="pref_header_input_preparation">Eingabe Vorbereitung</string>
<string name="pref_title_special_characters">Sonderzeichen</string>
<string name="pref_on_replace_special_characters">Ersetze Sonderzeichen mit ähnlichen Zeichen</string>
<string name="pref_off_replace_special_characters">Entferne Sonderzeichen aus der Nachricht</string>
<string name="pref_title_numeric_spelling_language">Zahlenbuchstabiersprache</string>
<string name="pref_description_numeric_spelling_language">Sprache in der Zahlen buchstabiert werden sollen.</string>
<string-array name="pref_list_numeric_spelling_language">

View file

@ -7,14 +7,14 @@
<string name="title_about_dialog">About EnigmAndroid</string>
<string name="description_text">EnigmAndroid is an implementation of a simulation of the Enigma Machine.
The Enigma Machine is a cypher machine developed in the 1920s. It was used by the german Wehrmacht to
encipher secret messaged during the second world war. There were multiple different Enigma models. For enciphering text, every letter is passed through 3-4 mechanical rotors that rotate with every keypress.
encipher secret messaged during the second world war. There were multiple different Enigma models. For enciphering text, every letter is passed through 3-4 mechanical rotors that rotate with every keystroke.
That way the enigma achieves polyalphabetic substitution and the output appears random. The rotors could be chosen from a set of 5. Additionally there was a
so called plugboard, where one could switch over pairs of letters.
</string>
<string name="title_section_how_to_use">How to use</string>
<string name="section_how_to_use">In the beginning, choose a model of the enigma machine to work with.
You can do this in the settings. To encrypt/decrpyt a message, you can type it into the input field.
You can do this in the settings. To encrypt/decrypt a message, you can name it into the input field.
Afterwards you can - depending on the chosen model - select a reflector and the some rotors. Also select their initial positions.
Then you may set pairs on the plugboard or on the pluggable reflector.
Therefore press the respective button and connect the characters you wish to connect by clicking them one after another.

View file

@ -13,10 +13,8 @@
<string name="action_settings">Settings</string>
<string name="action_send">Send</string>
<string name="send_to">Send to…</string>
<string name="message_choose_ringsettings">Choose ring-settings for the rotors:</string>
<string name="hint_enigma_type_here">Type here</string>
<string name="hint_enigma_code">EnigmaCode</string>
<string name="hint_enigma_plugboard">Plugboard (AZ,BE...)</string>
<string name="hint_rotor1">Rotor 1</string>
<string name="hint_rotor2">Rotor 2</string>
<string name="hint_rotor3">Rotor 3</string>
@ -30,9 +28,6 @@
<string name="hint_enigma_reflector_wiring">Wiring Reflector</string>
<string name="hint_passphrase">Enter passphrase</string>
<string name="button_crypt">En-/Decrypt!</string>
<string name="error_parsing_plugs">Error: Can\'t interpret plugboard input.</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_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>
@ -40,7 +35,6 @@
<string name="title_reflector_dialog">Reflector Wiring</string>
<string name="dialog_positiv">OK</string>
<string name="dialog_negativ">Cancel</string>
<string name="dialog_clear">Clear</string>
<string name="dialog_ringsettings_success">Set Ring-Settings to</string>
<string name="dialog_reflector_set">Rewired Reflector.</string>
<string name="dialog_plugboard_set">Plugged Plugboard.</string>

View file

@ -32,15 +32,8 @@
<item>R</item>
<item>T</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
to rotate twice, if it is one step before its turnover point.
</string>
<string name="pref_header_input_preparation">Input Preparation</string>
<string name="pref_title_special_characters">Special characters</string>
<string name="pref_on_replace_special_characters">Replace special characters with similar ones</string>
<string name="pref_off_replace_special_characters">Remove special characters from the message</string>
<string name="pref_title_numeric_spelling_language">Number spelling language</string>
<string name="pref_description_numeric_spelling_language">Language, in which numbers are spelled.</string>
<string-array name="pref_list_numeric_spelling_language">

View file

@ -9,20 +9,9 @@
android:entries="@array/pref_list_machine_type"
android:entryValues="@array/pref_alias_machine_type"
android:defaultValue="Enigma I"/>
<SwitchPreference
android:key="prefAnomaly"
android:title="@string/pref_title_simulate_anomaly"
android:summary="@string/pref_description_simulate_anomaly"
android:defaultValue="true" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_header_input_preparation">
<SwitchPreference
android:title="@string/pref_title_special_characters"
android:key="prefReplaceSpecialCharacters"
android:summaryOn="@string/pref_on_replace_special_characters"
android:summaryOff="@string/pref_off_replace_special_characters"
android:defaultValue="true"/>
<ListPreference
android:key="prefNumericLanguage"
android:title="@string/pref_title_numeric_spelling_language"

2
gradlew vendored
View file

@ -116,7 +116,7 @@ if $cygwin ; then
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -name d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"