First ever commit of all projectfiles

This commit is contained in:
vanitasvitae 2015-02-04 20:51:31 +01:00
commit f678a239ed
44 changed files with 1723 additions and 0 deletions

1
app/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

BIN
app/app-release.apk Normal file

Binary file not shown.

66
app/app.iml Normal file
View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EnigmAndroid" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
</content>
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

24
app/build.gradle Normal file
View file

@ -0,0 +1,24 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "de.vanitasvitae.enigmandroid"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

BIN
app/enigmandroid.apk Normal file

Binary file not shown.

17
app/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /media/Daten/android-studio/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View file

@ -0,0 +1,13 @@
package de.vanitasvitae.enigmandroid;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vanitasvitae.enigmandroid"
android:versionCode="00001"
android:versionName="04.02.2015-beta">
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,330 @@
package de.vanitasvitae.enigmandroid;
/**
* Enigma-machine
* @author vanitasvitae
*
*/
public class Enigma
{
private Plugboard plugboard;
private Rotor r1;
private Rotor r2;
private Rotor r3;
private Rotor ukw;
private static final int[] STANDARD_CONFIGURATION = {1,2,3,1,1,1,1};
private boolean showSteps;
private boolean verbose = false;
private String output = null;
/**
* @param pbconf two-dimensional Array with plugs, that need to be switched
* @param conf Configuration of the enigma
*/
public Enigma(char[][] pbconf, int[] conf) throws Plugboard.PlugAlreadyUsedException
{
if(conf!=null) konfiguration(conf);
else konfiguration(Enigma.STANDARD_CONFIGURATION);
this.setPlugboard(pbconf);
}
/**
* Encrypts / Decrypts a given String
* @param w Text to decrypt/encrypt
* @return
*/
public String encrypt(String w)
{
String k=w;
String c = "";
//for each char x in k
for(int i=0; i<k.length(); i++)
{
char x = k.charAt(i);
c = c + this.encryptChar(x);
}
return c;
}
/**
* Verschlüssele den übergebenen char k.
* Zähle danach Konfiguration hoch.
* @param k zu verschlüsselnder char
* @return verschlüsselter char
*/
public char encryptChar(char k)
{
//Move rotors
r1.incrementCounter();
if(r1.getCounter() == r1.getRingsetting()) {
r2.incrementCounter();
if (r2.getCounter() == r2.getRingsetting()) {
r3.incrementCounter();
}
}
int x = (int) k;
x = x-65; //Remove Unicode Offset (A=65 in Unicode.)
//Encryption
//forward direction
x = plugboard.encrypt(x);
x =(x + r1.getCounter())%26;
x = r1.encryptForward(x);
x = (x + r2.getCounter()- r1.getCounter())%26;
x = r2.encryptForward(x);
x = (x + r3.getCounter()- r2.getCounter())%26;
x = r3.encryptForward(x);
x = (26 + x - r3.getCounter())%26;
//backward direction
x = ukw.encryptForward(x);
x = (26 + x + r3.getCounter())%26;
x = r3.encryptBackward(x);
x = (26 + x - r3.getCounter()+ r2.getCounter())%26;
x = r2.encryptBackward(x);
x = (26 + x - r2.getCounter()+ r1.getCounter())%26;
x = r1.encryptBackward(x);
x = (26 + x - r1.getCounter())%26;
x = plugboard.encrypt(x);
return (char) (x+65); //Add Offset
}
/**
* Prepare String for encryption via enigma
* Replace . , ! ? : with X
* Remove all other chars that are not A..Z
* @param word string
* @return prepared string
*/
public static String prepare(String word)
{
String w = word.toUpperCase();
String c = "";
for(int i=0; i<w.length(); i++)
{
char x = w.charAt(i);
if(x>=65 && x<=90) //If x in [A..Z]
{
c = c + x; //Append to String
}
//if x is special symbol
else
{
if(x == '.' || x == ',' || x == '!' || x == '?' || x == ':')
{
//replace x with X and encrypt
c = c + 'X';
}
}
}
return c;
}
/**
* Create Plugboard configuration from String.
* String must be in format XY:AZ and so on.
* X and Y are plugs, that will be switched over.
* Dont do things such as AA or AB:CA. This will cause Exceptions
* @param p String
* @return Array
*/
public static char[][] parsePlugs(String p) throws InvalidPlugboardConfigurationFormatException
{
if(p.length()==0)
{
return null;
}
String[] in = p.toUpperCase().split(",");
if(in.length!=(p.length()+1)/3)
{
throw new InvalidPlugboardConfigurationFormatException("Fehler beim Parsen der Plugs: Fehlercode 1");
}
else
{
char[][] plugs = new char[(p.length()+1)/3][2];
int i=0;
for(String x:in)
{
if(x.length()!=2)
{
throw new InvalidPlugboardConfigurationFormatException("Fehler beim Parsen der Plugs: Fehlercode 2");
}
else
{
plugs[i] = x.toCharArray();
i++;
}
}
return plugs;
}
}
public void setPlugboard(char[][] c) throws Plugboard.PlugAlreadyUsedException
{
plugboard = new Plugboard();
if(c!=null)
{
for(int i=0; i<c.length; i++)
{
plugboard.setPlug(c[i][0], c[i][1]);
}
}
}
/**
* Set config of the enigma
* @param conf configuration
*/
public void konfiguration(int[] conf)
{
if(conf.length!=7)
{
konfiguration(Enigma.STANDARD_CONFIGURATION);
}
else
{
int ro1 = conf[0];
int ro2 = conf[1];
int ro3 = conf[2];
int ukwN = conf[3];
int r1stand = 26+conf[4]-1;
int r2stand = 26+conf[5]-1;
int r3stand = 26+conf[6]-1;
//Lege erste Walze fest
switch(ro1)
{
case 1:
{
r1 = new Rotor('1',(r1stand)%26,0);
break;
}
case 2:
{
r1 = new Rotor('2',(r1stand)%26,0);
break;
}
case 3:
{
r1 = new Rotor('3',(r1stand)%26,0);
break;
}
case 4:
{
r1 = new Rotor('4',(r1stand)%26,0);
break;
}
case 5:
{
r1 = new Rotor('5',(r1stand)%26,0);
break;
}
}
//Lege zweite Walze fest
switch(ro2)
{
case 1:
{
r2 = new Rotor('1',(r2stand)%26,0);
break;
}
case 2:
{
r2 = new Rotor('2',(r2stand)%26,0);
break;
}
case 3:
{
r2 = new Rotor('3',(r2stand)%26,0);
break;
}
case 4:
{
r2 = new Rotor('4',(r2stand)%26,0);
break;
}
case 5:
{
r2 = new Rotor('5',(r2stand)%26,0);
break;
}
}
//Lege dritte Walze fest
switch(ro3)
{
case 1:
{
r3 = new Rotor('1',(r3stand)%26,0);
break;
}
case 2:
{
r3 = new Rotor('2',(r3stand)%26,0);
break;
}
case 3:
{
r3 = new Rotor('3',(r3stand)%26,0);
break;
}
case 4:
{
r3 = new Rotor('4',(r3stand)%26,0);
break;
}
case 5:
{
r3 = new Rotor('5',(r3stand)%26,0);
break;
}
}
//Lege Umkehrwalze fest
switch(ukwN)
{
case 1:
{
ukw = new Rotor('A',0,0);
break;
}
case 2:
{
ukw = new Rotor('B',0,0);
break;
}
case 3:
{
ukw = new Rotor('C',0,0);
break;
}
}
}
}
public int[] getKonfiguration()
{
int[] c = new int[7];
{
c[0] = r1.getType();
c[1] = r2.getType();
c[2] = r3.getType();
c[3] = ukw.getType();
c[4] = r1.getCounter();
c[5] = r2.getCounter();
c[6] = r3.getCounter();
}
return c;
}
public static class InvalidPlugboardConfigurationFormatException extends Exception
{
public InvalidPlugboardConfigurationFormatException(String m)
{
super(m);
}
}
}

View file

@ -0,0 +1,188 @@
package de.vanitasvitae.enigmandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.widget.Toast;
public class MainActivity extends Activity
{
private Spinner w1;
private Spinner w2;
private Spinner w3;
private Spinner reversingRotor;
private Spinner w1pos;
private Spinner w2pos;
private Spinner w3pos;
private EditText plugboard;
private EditText input;
private EditText output;
private Enigma enigma;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.initLayout();
this.reset();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_version)
{
Toast.makeText(getApplicationContext(), R.string.version,
Toast.LENGTH_SHORT).show();
return true;
}
else if(id == R.id.action_reset)
{
reset();
}
return super.onOptionsItemSelected(item);
}
public void setEnigma(View v)
{
int[] conf = new int[7];
conf[0] = w1.getSelectedItemPosition()+1;
conf[1] = w2.getSelectedItemPosition()+1;
conf[2] = w3.getSelectedItemPosition()+1;
conf[3] = reversingRotor.getSelectedItemPosition()+1;
conf[4] = w1pos.getSelectedItemPosition()+1;
conf[5] = w2pos.getSelectedItemPosition()+1;
conf[6] = w3pos.getSelectedItemPosition()+1;
try
{
enigma = new Enigma(null,null);
}
catch(Plugboard.PlugAlreadyUsedException e)
{}
char[][] pbconf = null;
try
{
pbconf = Enigma.parsePlugs(plugboard.getText().toString());
}
catch(Enigma.InvalidPlugboardConfigurationFormatException e)
{
String error = this.getResources().getString(R.string.error_parsing_plugs)+": "+e.getMessage();
Toast.makeText(getApplicationContext(), error,
Toast.LENGTH_SHORT).show();
}
try
{
enigma.konfiguration(conf);
enigma.setPlugboard(pbconf);
}
catch(Plugboard.PlugAlreadyUsedException e)
{
Toast.makeText(this.getApplicationContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();;
}
}
public void crypto(View v)
{
setEnigma(null);
String m = input.getText().toString();
m = Enigma.prepare(m);
input.setText(m);
output.setText(enigma.encrypt(m));
updateSpinner(enigma.getKonfiguration());
}
private void reset()
{
w1.setSelection(0);
w2.setSelection(1);
w3.setSelection(2);
reversingRotor.setSelection(0);
w1pos.setSelection(0);
w2pos.setSelection(0);
w3pos.setSelection(0);
plugboard.setText("");
input.setText("");
output.setText("");
}
private void initLayout()
{
w1 = (Spinner) findViewById(R.id.w1);
ArrayAdapter<CharSequence> w1adapter = ArrayAdapter.createFromResource(this,
R.array.enigma_walzen, android.R.layout.simple_spinner_item);
w1adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w1.setAdapter(w1adapter);
w2 = (Spinner) findViewById(R.id.w2);
ArrayAdapter<CharSequence> w2adapter = ArrayAdapter.createFromResource(this,
R.array.enigma_walzen, android.R.layout.simple_spinner_item);
w2adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w2.setAdapter(w2adapter);
w3 = (Spinner) findViewById(R.id.w3);
ArrayAdapter<CharSequence> w3adapter = ArrayAdapter.createFromResource(this,
R.array.enigma_walzen, android.R.layout.simple_spinner_item);
w3adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w3.setAdapter(w3adapter);
reversingRotor = (Spinner) findViewById(R.id.ukw);
ArrayAdapter<CharSequence> ukwadapter = ArrayAdapter.createFromResource(this,
R.array.enigma_ukw, android.R.layout.simple_spinner_item);
ukwadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
reversingRotor.setAdapter(ukwadapter);
w1pos = (Spinner) findViewById(R.id.w1pos);
ArrayAdapter<CharSequence> w1posadapter = ArrayAdapter.createFromResource(this,
R.array.positions, android.R.layout.simple_spinner_item);
w1posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w1pos.setAdapter(w1posadapter);
w2pos = (Spinner) findViewById(R.id.w2pos);
ArrayAdapter<CharSequence> w2posadapter = ArrayAdapter.createFromResource(this,
R.array.positions, android.R.layout.simple_spinner_item);
w2posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w2pos.setAdapter(w2posadapter);
w3pos = (Spinner) findViewById(R.id.w3pos);
ArrayAdapter<CharSequence> w3posadapter = ArrayAdapter.createFromResource(this,
R.array.positions, android.R.layout.simple_spinner_item);
w3posadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
w3pos.setAdapter(w3posadapter);
plugboard = (EditText) findViewById(R.id.plugboard);
input = (EditText) findViewById(R.id.input);
output = (EditText) findViewById(R.id.output);
}
public void updateSpinner(int[] c)
{
w1.setSelection(c[0]-1);
w2.setSelection(c[1]-1);
w3.setSelection(c[2]-1);
w1pos.setSelection(c[4]);
w2pos.setSelection(c[5]);
w3pos.setSelection(c[6]);
}
}

View file

@ -0,0 +1,94 @@
package de.vanitasvitae.enigmandroid;
/**
* Klasse für das Steckerbrett der Enigma
* @author vanitas
*
*/
public class Plugboard
{
//Plugboard
// Q W E R T Z U I O
// A S D F G H J K
// P Y X C V B N M L
//Array für die Steckerverbindungen
int[] pb;
//Vergleichsarray (Keine Stecker)
public static final int[] ref = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
/**
* Erzeuge neues Plugboard ohne Steckverbindungen
*/
public Plugboard()
{
pb = new int[26];
resetPlugboard();
}
/**
* Verschlüssele den gegebenen Buchstaben, den Regeln des Plugboard folgend
* @param x zu verschlüsselndes Zeichen
* @return Verschlüsseltes Zeichen
*/
public int encrypt(int x)
{
return pb[x];
}
/**
* Setze das Plugboard in den Standardzustand (Keine Stecker)
*/
public void resetPlugboard()
{
pb = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
}
public void setPlugs(char[][] p) throws PlugAlreadyUsedException
{
for(int i=0; i<p.length; i++)
{
if(p[i]!=null)
{
this.setPlug(p[i][0], p[i][1]);
}
}
}
/**
* Steckere Buchstaben a und b auf dem Plugboard
* @param a first Plug
* @param b second Plug
*/
public void setPlug(char a, char b) throws PlugAlreadyUsedException
{
//Verhindere, dass Buchstabe mit sich selbst gesteckert wird
if(a==b)
{
throw new PlugAlreadyUsedException("Unable to plug "+a +" to " +a);
}
int x = a-65;
int y = b-65;
//Check, if plugs already steckered
if(pb[x]!=ref[x])
{
throw new PlugAlreadyUsedException("Plug " + a + " used twice!");
}
else if(pb[y]!=ref[y])
{
throw new PlugAlreadyUsedException("Plug " + b + " used twice!");
}
else //Steckere um
{
int c =pb[x];
pb[x] = pb[y];
pb[y] = c;
}
}
public static class PlugAlreadyUsedException extends Exception
{
public PlugAlreadyUsedException(String m)
{
super(m);
}
}
}

View file

@ -0,0 +1,194 @@
package de.vanitasvitae.enigmandroid;
/**
* Klasse, die eine Walze der Enigmamaschine representiert (I-V,A-C)
* @author vanitas
*
*/
public class Rotor
{
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
//ABC: 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
//Rotor1: 'E','K','M','F','L','G','D','Q','V','Z','N','T','O','W','Y','H','X','U','S','P','A','I','B','R','C','J'
//Rotor2: 'A','J','D','K','S','I','R','U','X','B','L','H','W','T','M','C','Q','G','Z','N','P','Y','F','V','O','E'
//Rotor3: 'B','D','F','H','J','L','C','P','R','T','X','V','Z','N','Y','E','I','W','G','A','K','M','U','S','Q','O'
//Rotor4: 'E','S','O','V','P','Z','J','A','Y','Q','U','I','R','H','X','L','N','F','T','G','K','D','C','M','W','B'
//Rotor5: 'V','Z','B','R','G','I','T','Y','U','P','S','D','N','H','L','X','A','W','M','J','Q','O','F','E','C','K'
//Reversing Rotor A: AE BJ CM DZ FL GY HX IV KW NR OQ PU ST
//Reversing Rotor B: AY BR CU DH EQ FS GL IP JX KN MO TZ VW
//Reversing Rotor C: AF BV CP DJ EI GO HY KR LZ MX NW QT SU
//Original rotors
public static final Integer[] rotor1 = {4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9};
public static final Integer[] rotor2 = {0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4};
public static final Integer[] rotor3 = {1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14};
public static final Integer[] rotor4 = {4,18,14,21,15,25,9,0,24,16,20,8,17,7,23,11,13,5,19,6,10,3,2,12,22,1};
public static final Integer[] rotor5 = {21,25,1,17,6,8,19,24,20,15,18,3,13,7,11,23,0,22,12,9,16,14,5,4,2,10};
//Original rotors backwards direction
public static final Integer[] backwardsRotor1 = {20,22,24,6,0,3,5,15,21,25,1,4,2,10,12,19,7,23,18,11,17,8,13,16,14,9};
public static final Integer[] backwardsRotor2 = {0,9,15,2,25,22,17,11,5,1,3,10,14,19,24,20,16,6,4,13,7,23,12,8,21,18};
public static final Integer[] backwardsRotor3 = {19,0,6,1,15,2,18,3,16,4,20,5,21,13,25,7,24,8,23,9,22,11,17,10,14,12};
public static final Integer[] backwardsRotor4 = {7,25,22,21,0,17,19,13,11,6,20,15,23,16,2,4,9,12,1,18,10,3,24,14,8,5};
public static final Integer[] backwardsRotor5 = {16,2,24,11,23,22,4,13,5,19,25,14,18,12,21,9,20,3,10,6,8,0,17,15,7,1};
//Original reversing rotors A,B,C, D, E,F, G, H, I, J,K, L,M,N, O, P, Q, R, S, T, U, V,W, X,Y,Z
public static final Integer[] reversingRotorA = {4,9,12,25,0,11,24,23,21,1,22,5,2,17,16,20,14,13,19,18,15,8,10,7,6,3};
public static final Integer[] reversingRotorB = {24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19};
public static final Integer[] reversingRotorC = {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};
private Integer[] rotor; //choose one of rotor1-5
private Integer[] rrotor; //choose one of backwardsRotor1-5
private int ringsetting;
private int counter;
private String name;
private int type;
/**
* Create new Rotor (1 - 5 = normal rotor, -1 - -3 = reversing rotor)
* @param type integer determines type
* @param setting setting (rotation) of the rotor
*/
public Rotor(char type, int setting, int ring)
{
this.ringsetting = ring%26;
switch(type)
{
case '1':
{
this.rotor = rotor1;
this.rrotor = backwardsRotor1;
this.counter = setting;
this.name="I";
this.type = 1;
break;
}
case '2':
{
this.rotor = rotor2;
this.rrotor = backwardsRotor2;
this.counter = setting;
this.name="II";
this.type = 2;
break;
}
case '3':
{
this.rotor = rotor3;
this.rrotor = backwardsRotor3;
this.counter = setting;
this.name="III";
this.type = 3;
break;
}
case '4':
{
this.rotor = rotor4;
this.rrotor = backwardsRotor4;
this.counter = setting;
this.name="IV";
this.type = 4;
break;
}
case '5':
{
this.rotor = rotor5;
this.rrotor = backwardsRotor5;
this.counter = setting;
this.name="V";
this.type = 5;
break;
}
case 'A':
{
this.rotor = reversingRotorA;
this.rrotor = null;
this.counter = 0;
this.name="A";
this.type = 1;
break;
}
case 'B':
{
this.rotor = reversingRotorB;
this.rrotor = null;
this.counter = 0;
this.name="B";
this.type = 2;
break;
}
case 'C':
{
this.rotor = reversingRotorC;
this.rrotor = null;
this.counter = 0;
this.name="C";
this.type = 3;
break;
}
}
}
/**
* encrypt in forward direction (forward means first half of the cycle through the rotors)
* @param x incoming character
* @return encrypted character
*/
public int encryptForward(int x)
{
return this.rotor[(26+x)%26];
}
/**encrypt in backward direction (coming from the reversing rotor)
* @param x incoming character
* @return encrypted character
*/
public int encryptBackward(int x)
{
if(this.rrotor ==null) return this.rotor[(26+x)%26];
else return this.rrotor[(26+x)%26];
}
/**
* return rotation of the rotor
* @return rotation
*/
public int getCounter()
{
return this.counter;
}
/**
* increment rotation of the rotor by one.
*/
public void incrementCounter()
{
this.counter = (this.counter+1)%26;
}
/**
* Return the name of the rotor
* @return name
*/
public String getName()
{
return name;
}
/**
* Return ringsettings of the rotor (TODO: Find out, how ringsetting was implemented in original enigma. Wikipedia is not enough :/
* @return ringsetting
*/
public int getRingsetting()
{
return this.ringsetting;
}
/**
* Returns the integer, which was used to create this rotor. TODO: This is too resource hungry.
* @return
*/
public int getType()
{
return this.type;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View file

@ -0,0 +1,187 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/lin_lay_names_1">
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_ukw"/>
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w3"/>
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w2"/>
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/lin_lay_1"
android:layout_below="@+id/lin_lay_names_1">
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/ukw">
</Spinner>
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w3">
</Spinner>
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w2">
</Spinner>
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w1">
</Spinner>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/lin_lay_1"
android:id="@+id/lin_lay_names_2">
<Space
android:layout_width="0dp"
android:layout_weight=".125"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w3pos"/>
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w2pos"/>
<TextView
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:text="@string/hint_w1pos"/>
<Space
android:layout_width="0dp"
android:layout_weight=".125"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/lin_lay_2"
android:layout_below="@+id/lin_lay_names_2">
<Space
android:layout_width="0dp"
android:layout_weight=".125"
android:layout_height="wrap_content" />
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w3pos">
</Spinner>
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w2pos">
</Spinner>
<Spinner
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="wrap_content"
android:id="@+id/w1pos">
</Spinner>
<Space
android:layout_width="0dp"
android:layout_weight=".125"
android:layout_height="wrap_content" />
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="30pt"
android:id="@+id/plugboard"
android:hint="@string/hint_enigma_plugboard"
android:layout_below="@+id/lin_lay_2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/plugboard"
android:layout_above="@+id/buttons_lay"
android:id="@+id/text_layer">
<EditText
android:layout_width="0dp"
android:layout_weight=".50"
android:layout_height="match_parent"
android:id="@+id/input"
android:hint="@string/hint_enigma_usertype" />
<EditText
android:layout_width="0dp"
android:layout_weight=".50"
android:layout_height="match_parent"
android:editable="false"
android:textIsSelectable="true"
android:id="@+id/output"
android:hint="@string/hint_enigma_code"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttons_lay"
android:layout_alignParentBottom="true">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text_layer"
android:id="@+id/button_crypt"
android:onClick="crypto"
android:text="@string/button_crypt"/>
</LinearLayout>
</RelativeLayout>

View file

@ -0,0 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="@+id/action_version"
android:title="@string/action_version"
android:orderInCategory="100"
android:showAsAction="never" />
<item android:id="@+id/action_reset"
android:orderInCategory="99"
android:showAsAction="ifRoom"
android:title="@string/action_reset" />
</menu>

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">EnigmAndroid</string>
<string name="action_settings">Version</string>
<string name="hint_enigma_usertype">Hier Tippen</string>
<string name="hint_enigma_code">Enigma-Code</string>
<string name="hint_enigma_plugboard">Steckerbrett (AZ,BE...)</string>
<string name="hint_w1">Walze 1</string>
<string name="hint_w2">Walze 2</string>
<string name="hint_w3">Walze 3</string>
<string name="hint_ukw">Umkehr-\nWalze</string>
<string name="hint_w1pos">Position\nWalze 1</string>
<string name="hint_w2pos">Position\nWalze 2</string>
<string name="hint_w3pos">Position\nWalze 3</string>
<string name="button_crypt">Ver-/Entschlüsseln</string>
<string-array name="enigma_walzen">
<item>I</item>
<item>II</item>
<item>III</item>
<item>IV</item>
<item>V</item>
</string-array>
<string-array name="enigma_ukw">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
<string-array name="positions">
<item>A</item>
<item>B</item>
<item>C</item>
<item>D</item>
<item>E</item>
<item>F</item>
<item>G</item>
<item>H</item>
<item>I</item>
<item>J</item>
<item>K</item>
<item>L</item>
<item>M</item>
<item>N</item>
<item>O</item>
<item>P</item>
<item>Q</item>
<item>R</item>
<item>S</item>
<item>T</item>
<item>U</item>
<item>V</item>
<item>W</item>
<item>X</item>
<item>Y</item>
<item>Z</item>
</string-array>
</resources>

View file

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View file

@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="version" translatable="false">0.1-04.02.2015</string>
<string name="app_name">EnigmAndroid</string>
<string name="action_version">Version</string>
<string name="action_reset">Reset</string>
<string name="hint_enigma_usertype">Type here</string>
<string name="hint_enigma_code">EnigmaCode</string>
<string name="hint_enigma_plugboard">Plugboard (AZ,BE...)</string>
<string name="hint_w1">R1</string>
<string name="hint_w2">R2</string>
<string name="hint_w3">R3</string>
<string name="hint_ukw">RR</string>
<string name="hint_w1pos">PosR1</string>
<string name="hint_w2pos">PosR2</string>
<string name="hint_w3pos">PosR3</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-array name="enigma_walzen">
<item>I</item>
<item>II</item>
<item>III</item>
<item>IV</item>
<item>V</item>
</string-array>
<string-array name="enigma_ukw">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
<string-array name="positions">
<item>A</item>
<item>B</item>
<item>C</item>
<item>D</item>
<item>E</item>
<item>F</item>
<item>G</item>
<item>H</item>
<item>I</item>
<item>J</item>
<item>K</item>
<item>L</item>
<item>M</item>
<item>N</item>
<item>O</item>
<item>P</item>
<item>Q</item>
<item>R</item>
<item>S</item>
<item>T</item>
<item>U</item>
<item>V</item>
<item>W</item>
<item>X</item>
<item>Y</item>
<item>Z</item>
</string-array>
</resources>

View file

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>