commit f678a239eddce4412ba8bfb809c1043426772326 Author: vanitasvitae Date: Wed Feb 4 20:51:31 2015 +0100 First ever commit of all projectfiles diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..cbaec62 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +EnigmAndroid \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/dictionaries/vanitas.xml b/.idea/dictionaries/vanitas.xml new file mode 100644 index 0000000..7ef52d1 --- /dev/null +++ b/.idea/dictionaries/vanitas.xml @@ -0,0 +1,7 @@ + + + + plugboard + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..736c7b5 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..671eade --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + Android API 19 Platform + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..51d776b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..276779e --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/EnigmAndroid.iml b/EnigmAndroid.iml new file mode 100644 index 0000000..0bb6048 --- /dev/null +++ b/EnigmAndroid.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app-release.apk b/app/app-release.apk new file mode 100644 index 0000000..962386b Binary files /dev/null and b/app/app-release.apk differ diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..032b5df --- /dev/null +++ b/app/app.iml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e423fed --- /dev/null +++ b/app/build.gradle @@ -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']) +} diff --git a/app/enigmandroid.apk b/app/enigmandroid.apk new file mode 100644 index 0000000..962386b Binary files /dev/null and b/app/enigmandroid.apk differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..a841cdf --- /dev/null +++ b/app/proguard-rules.pro @@ -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 *; +#} diff --git a/app/src/androidTest/java/de/vanitasvitae/enigmandroid/ApplicationTest.java b/app/src/androidTest/java/de/vanitasvitae/enigmandroid/ApplicationTest.java new file mode 100644 index 0000000..5e12da5 --- /dev/null +++ b/app/src/androidTest/java/de/vanitasvitae/enigmandroid/ApplicationTest.java @@ -0,0 +1,13 @@ +package de.vanitasvitae.enigmandroid; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d6afe98 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java new file mode 100644 index 0000000..37d4855 --- /dev/null +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/Enigma.java @@ -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=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 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 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 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 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 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 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 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]); + } +} diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java new file mode 100644 index 0000000..a521acd --- /dev/null +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/Plugboard.java @@ -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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +