summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:43:46 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:43:46 +0200
commitc9dd9469183d95c6c2f4d01e3d6365ec57386a65 (patch)
tree07ec933179eced02eec8a70f8b64c9281d453457 /src
Initial commitHEADmaster
Diffstat (limited to 'src')
-rwxr-xr-xsrc/Core.java8
-rwxr-xr-xsrc/Mainframe.java78
-rwxr-xr-xsrc/algorithmus/Algorithmus.java13
-rwxr-xr-xsrc/algorithmus/Autokey.java103
-rwxr-xr-xsrc/algorithmus/Blabla.java116
-rwxr-xr-xsrc/algorithmus/Caesar.java96
-rwxr-xr-xsrc/algorithmus/Case.java81
-rwxr-xr-xsrc/algorithmus/Constants.java13
-rwxr-xr-xsrc/algorithmus/Palisaden.java72
-rwxr-xr-xsrc/algorithmus/Utils.java39
-rwxr-xr-xsrc/algorithmus/Vigenere.java99
-rwxr-xr-xsrc/algorithmus/XOR.java102
-rwxr-xr-xsrc/algorithmus/Zaehlen.java55
13 files changed, 875 insertions, 0 deletions
diff --git a/src/Core.java b/src/Core.java
new file mode 100755
index 0000000..b965eff
--- /dev/null
+++ b/src/Core.java
@@ -0,0 +1,8 @@
+
+public class Core {
+
+ public static void main(String[] args) {
+ new Mainframe().setVisible(true);
+ }
+
+}
diff --git a/src/Mainframe.java b/src/Mainframe.java
new file mode 100755
index 0000000..e486e2a
--- /dev/null
+++ b/src/Mainframe.java
@@ -0,0 +1,78 @@
+import java.awt.TextArea;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import algorithmus.Algorithmus;
+import algorithmus.Autokey;
+import algorithmus.Blabla;
+import algorithmus.Caesar;
+import algorithmus.Case;
+import algorithmus.Palisaden;
+import algorithmus.Vigenere;
+import algorithmus.XOR;
+import algorithmus.Zaehlen;
+
+
+public class Mainframe extends JFrame {
+
+ private JTextArea input, output;
+ private JScrollPane scrollInput, scrollOutput;
+ private JComboBox combo;
+ private JButton options, encode, decode;
+ private Algorithmus[] algo = new Algorithmus[] { new Case(), new Caesar(), new Blabla(), new Zaehlen(), new Vigenere(), new XOR(), new Autokey(), new Palisaden() };
+
+ public Mainframe() {
+ this.setLayout(null);
+ this.setResizable(false);
+ this.setTitle("Kryptographie");
+ this.setSize(500, 500);
+ input = new JTextArea();
+ input.setLineWrap(true);
+ scrollInput = new JScrollPane(input);
+ scrollInput.setBounds(5, 5, 470, 205);
+ output = new JTextArea();
+ output.setEditable(false);
+ output.setLineWrap(true);
+ scrollOutput = new JScrollPane(output);
+ scrollOutput.setBounds(5, 245, 470, 205);
+ String[] names = new String[algo.length];
+ for(int i = 0; i<names.length; i++)
+ names[i] = algo[i].getName();
+ combo = new JComboBox(names);
+ combo.setBounds(5, 215, 150, 20);
+ options = new JButton("Options");
+ options.setBounds(160, 215, 100, 20);
+ options.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ algo[combo.getSelectedIndex()].options();
+ }
+ });
+ encode = new JButton("Encode");
+ encode.setBounds(270, 215, 100, 20);
+ encode.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ output.setText(algo[combo.getSelectedIndex()].encode(input.getText()));
+ }
+ });
+ decode = new JButton("Decode");
+ decode.setBounds(375, 215, 100, 20);
+ decode.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ output.setText(algo[combo.getSelectedIndex()].decode(input.getText()));
+ }
+ });
+ this.getContentPane().add(scrollInput);
+ this.getContentPane().add(scrollOutput);
+ this.add(combo);
+ this.add(encode);
+ this.add(decode);
+ this.add(options);
+ }
+
+}
diff --git a/src/algorithmus/Algorithmus.java b/src/algorithmus/Algorithmus.java
new file mode 100755
index 0000000..f688e62
--- /dev/null
+++ b/src/algorithmus/Algorithmus.java
@@ -0,0 +1,13 @@
+package algorithmus;
+
+public abstract class Algorithmus {
+
+ public abstract void options();
+
+ public abstract String getName();
+
+ public abstract String encode(String input);
+
+ public abstract String decode(String input);
+
+}
diff --git a/src/algorithmus/Autokey.java b/src/algorithmus/Autokey.java
new file mode 100755
index 0000000..0d106f7
--- /dev/null
+++ b/src/algorithmus/Autokey.java
@@ -0,0 +1,103 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class Autokey extends Algorithmus {
+
+ private String name, key;
+ private char[] chars;
+
+ public Autokey() {
+ name = "Autokey";
+ key = "";
+ chars = new char[] { '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',
+ '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',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', ' '};
+ }
+
+ @Override
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Autokey");
+ frame.setSize(200, 150);
+ TextField keyField = new TextField();
+ keyField.setText(key);
+ keyField.setBounds(5, 5, 150, 20);
+ TextField alphabet = new TextField();
+ String alphaText = "";
+ for(int i = 0; i<chars.length; i++) {
+ alphaText += chars[i];
+ }
+ alphabet.setText(alphaText);
+ alphabet.setBounds(5, 30, 150, 20);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 55, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String alpha = alphabet.getText();
+ chars = new char[alpha.length()];
+ for(int i = 0; i<chars.length; i++) {
+ chars[i] = alpha.charAt(i);
+ }
+ key = keyField.getText();
+ }
+ });
+ frame.add(keyField);
+ frame.add(alphabet);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String encode(String input) {
+ int[][] arr = new int[2][input.length()];
+ String out = "";
+ for(int i = 0; i<arr[0].length; i++) {
+ char inc = input.charAt(i), pc;
+ if(i<key.length())
+ pc = key.charAt(i);
+ else
+ pc = input.charAt(i-key.length());
+ for(int x = 0; x<chars.length; x++) {
+ if(inc == chars[x])
+ arr[0][i] = x;
+ if(pc == chars[x])
+ arr[1][i] = x;
+ }
+ out += chars[(arr[0][i]+arr[1][i])%chars.length];
+ }
+ return out;
+ }
+
+ @Override
+ public String decode(String input) {
+ int[][] arr = new int[2][input.length()];
+ String out = "";
+ for(int i = 0; i<arr[0].length; i++) {
+ char inc = input.charAt(i), pc = key.charAt(i%key.length());
+ for(int x = 0; x<chars.length; x++) {
+ if(inc == chars[x])
+ arr[0][i] = x;
+ if(pc == chars[x])
+ arr[1][i] = x;
+ }
+ out += chars[((arr[0][i]-arr[1][i])+chars.length)%chars.length];
+ }
+ return out;
+ }
+
+}
diff --git a/src/algorithmus/Blabla.java b/src/algorithmus/Blabla.java
new file mode 100755
index 0000000..e459645
--- /dev/null
+++ b/src/algorithmus/Blabla.java
@@ -0,0 +1,116 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.UnsupportedEncodingException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class Blabla extends Algorithmus {
+
+ private String name, pw;
+ private char[] charset;
+
+ public Blabla() {
+ name = "Blabla";
+ }
+
+ public void options() {
+ charset = new char[] { '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',
+ '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',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', ' '};
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Blabla");
+ frame.setSize(200, 150);
+ TextField alphabet = new TextField();
+ alphabet.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄÖÜäöüß ");
+ alphabet.setBounds(5, 5, 150, 20);
+ TextField password = new TextField();
+ password.setText("Passwort");
+ password.setBounds(5, 30, 150, 20);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 55, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pw = password.getText();
+ String alpha = alphabet.getText();
+ charset = new char[alpha.length()];
+ alpha.getChars(0, alpha.length(), charset, 0);
+ }
+ });
+ frame.add(alphabet);
+ frame.add(password);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String encode(String input) {
+ int sum = getSum(pw, "UTF8"), length = input.length();
+ String out = "";
+ byte[] ba = Utils.fill(new byte[64], length), inba = null;
+ System.out.println(ba.length);
+ try {
+ inba = input.getBytes("UTF8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ for(int i = 0; i<length; i++) {
+ ba[(i/(length+1))*64] = inba[i];
+ }
+ //
+ for(int i = 0; i<ba.length; i++) {
+ if(ba[i] == 0x00)
+ out += "0";
+ else
+ out += ba[i];
+ }
+ //
+ return out;
+ }
+
+ public String decode(String input) {
+ int sum = getSum(pw, "UTF8"), length = input.length();
+ byte[] bin = null;
+ String str = "";
+ try {
+ for(int i = length/64; i>=0; i--) {
+ bin = Utils.fill(input.substring((i*64)-64, (i*64)).getBytes("UTF8"), 64);
+ sum = bin.length * 64;
+ for(int x = bin.length; x>0; x--) {
+ str += Constants.LETTERS_NUMBERS[(sum-=(bin[x]+x))%62];
+ }
+ }
+ } catch(UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return str;
+ }
+
+ public int getSum(String str, String charset) {
+ int sum = 0;
+ byte[] ba = new byte[] { (byte)0x00 };
+ try {
+ ba = str.getBytes(charset);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ for(int i = 0; i<ba.length; i++)
+ sum += ba[i];
+ return sum;
+ }
+
+ private int f(int x) {
+ return x^2;
+ }
+
+}
diff --git a/src/algorithmus/Caesar.java b/src/algorithmus/Caesar.java
new file mode 100755
index 0000000..1404272
--- /dev/null
+++ b/src/algorithmus/Caesar.java
@@ -0,0 +1,96 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class Caesar extends Algorithmus {
+
+ private String name;
+ private char[] chars;
+ private int v;
+
+ public Caesar() {
+ name = "Caesar";
+ chars = new char[] { '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',
+ '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',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', ' '};
+ v = 13;
+ }
+
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Caesar");
+ frame.setSize(200, 150);
+ TextField alphabet = new TextField();
+ String alphaText = "";
+ for(int i = 0; i<chars.length; i++) {
+ alphaText += chars[i];
+ }
+ alphabet.setText(alphaText);
+ alphabet.setBounds(5, 5, 150, 20);
+ JLabel label = new JLabel("Verschiebung:");
+ label.setBounds(5, 30, 100, 20);
+ JSpinner spinner = new JSpinner();
+ spinner.setBounds(100, 30, 50, 20);
+ spinner.setValue(v);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 55, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String alpha = alphabet.getText();
+ chars = new char[alpha.length()];
+ for(int i = 0; i<chars.length; i++) {
+ chars[i] = alpha.charAt(i);
+ }
+ v = (int) spinner.getValue();
+ }
+ });
+ frame.add(alphabet);
+ frame.add(label);
+ frame.add(spinner);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String encode(String input) {
+ String out = "";
+ for(int i = 0, size = input.length(); i<size; i++) {
+ for(int x = 0; x<chars.length; x++) {
+ if(chars[x] == input.charAt(i)) {
+ out += chars[(x + v) % chars.length];
+ }
+ }
+ }
+ return out;
+ }
+
+ public String decode(String input) {
+ String out = "";
+ int pos = 0;
+ for(int i = 0, size = input.length(); i<size; i++) {
+ for(int x = 0; x<chars.length; x++) {
+ if(chars[x] == input.charAt(i)) {
+ pos = (x - v);
+ if(pos<=0)
+ pos += chars.length;
+ out += chars[pos % chars.length];
+ }
+ }
+ }
+ return out;
+ }
+
+}
diff --git a/src/algorithmus/Case.java b/src/algorithmus/Case.java
new file mode 100755
index 0000000..06e35d6
--- /dev/null
+++ b/src/algorithmus/Case.java
@@ -0,0 +1,81 @@
+package algorithmus;
+
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.UnsupportedEncodingException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+
+public class Case extends Algorithmus {
+
+ private String name = "Case";
+ private boolean low = true;
+
+ public String getName() {
+ return name;
+ }
+
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Case");
+ frame.setSize(100, 100);
+ frame.setResizable(false);
+ Checkbox cb = new Checkbox("To Lowercase");
+ cb.setBounds(5, 5, 100, 20);
+ JButton apply = new JButton("Apply");
+ apply.setBounds(5, 30, 75, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ low = cb.getState();
+ }
+ });
+ frame.add(cb);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ public String encode(String input) {
+ try {
+ if(low)
+ return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
+ else
+ return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "Error";
+ }
+ }
+
+ public String decode(String input) {
+ try {
+ if(low)
+ return new String(upper(input.getBytes("US-ASCII")), "US-ASCII");
+ else
+ return new String(lower(input.getBytes("US-ASCII")), "US-ASCII");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "Error";
+ }
+ }
+
+ private byte[] upper(byte[] ba) {
+ for(int i = 0; i<ba.length; i++)
+ if(ba[i] > 96 && ba[i] < 123)
+ ba[i] -= 32;
+ return ba;
+ }
+
+ private byte[] lower(byte[] ba) {
+ for(int i = 0; i<ba.length; i++)
+ if(ba[i] > 64 && ba[i] < 91)
+ ba[i] += 32;
+ return ba;
+ }
+
+}
diff --git a/src/algorithmus/Constants.java b/src/algorithmus/Constants.java
new file mode 100755
index 0000000..87772d0
--- /dev/null
+++ b/src/algorithmus/Constants.java
@@ -0,0 +1,13 @@
+package algorithmus;
+
+public class Constants {
+
+ public static final char[] HEX_CHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ public static final char[] LETTERS_NUMBERS = new char[] {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ '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',
+ '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'
+ };
+
+}
diff --git a/src/algorithmus/Palisaden.java b/src/algorithmus/Palisaden.java
new file mode 100755
index 0000000..fa822d4
--- /dev/null
+++ b/src/algorithmus/Palisaden.java
@@ -0,0 +1,72 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class Palisaden extends Algorithmus {
+
+ private String name;
+ private int n;
+
+ public Palisaden() {
+ name = "Palisaden";
+ n = 3;
+ }
+
+ @Override
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Palisaden");
+ frame.setSize(200, 150);
+ JLabel label = new JLabel("Reihen:");
+ label.setBounds(5, 30, 100, 20);
+ JSpinner spinner = new JSpinner();
+ spinner.setBounds(100, 30, 50, 20);
+ spinner.setValue(n);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 55, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ n = (int) spinner.getValue();
+ }
+ });
+ frame.add(label);
+ frame.add(spinner);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String encode(String input) {
+ String out = "";
+ int length = input.length();
+ String[] rows = new String[n];
+ for(int i = 0; i<n; i++)
+ rows[i] = "";
+ for(int i = 0; i<length; i++) {
+ rows[i%n] += input.charAt(i);
+ }
+ for(int i = 0; i<n; i++)
+ out += rows[i] + "\n";
+ return out;
+ }
+
+ @Override
+ public String decode(String input) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/algorithmus/Utils.java b/src/algorithmus/Utils.java
new file mode 100755
index 0000000..6d1d7cf
--- /dev/null
+++ b/src/algorithmus/Utils.java
@@ -0,0 +1,39 @@
+package algorithmus;
+
+import java.util.Arrays;
+
+public class Utils {
+
+ public static byte[] crop(byte[] arr) {
+ for(int i = 0; i<arr.length; i++)
+ if(arr[i] == (byte)0x00)
+ return Arrays.copyOfRange(arr, 0, i);
+ return arr;
+ }
+
+ public static byte[] fill(byte[] arr, int length) {
+ return Arrays.copyOf(arr, length);
+ }
+
+ public static int inArr(Object[] arr, Object tofind) {
+ for(int i = 0; i<arr.length; i++)
+ if(arr[i] == tofind)
+ return i;
+ return 0;
+ }
+
+ public static int inArr(char[] arr, char tofind) {
+ for(int i = 0; i<arr.length; i++)
+ if(arr[i] == tofind)
+ return i;
+ return 0;
+ }
+
+ public static int inArrEq(Object[] arr, Object tofind) {
+ for(int i = 0; i<arr.length; i++)
+ if(arr[i].equals(tofind))
+ return i;
+ return 0;
+ }
+
+}
diff --git a/src/algorithmus/Vigenere.java b/src/algorithmus/Vigenere.java
new file mode 100755
index 0000000..9f429b7
--- /dev/null
+++ b/src/algorithmus/Vigenere.java
@@ -0,0 +1,99 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class Vigenere extends Algorithmus {
+
+ private String name, key;
+ private char[] chars;
+
+ public Vigenere() {
+ name = "Vigenere";
+ key = "";
+ chars = new char[] { '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',
+ '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',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', ' '};
+ }
+
+ @Override
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("Vigenere");
+ frame.setSize(200, 150);
+ TextField keyField = new TextField();
+ keyField.setText(key);
+ keyField.setBounds(5, 5, 150, 20);
+ TextField alphabet = new TextField();
+ String alphaText = "";
+ for(int i = 0; i<chars.length; i++) {
+ alphaText += chars[i];
+ }
+ alphabet.setText(alphaText);
+ alphabet.setBounds(5, 30, 150, 20);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 55, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String alpha = alphabet.getText();
+ chars = new char[alpha.length()];
+ for(int i = 0; i<chars.length; i++) {
+ chars[i] = alpha.charAt(i);
+ }
+ key = keyField.getText();
+ }
+ });
+ frame.add(keyField);
+ frame.add(alphabet);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String encode(String input) {
+ int[][] arr = new int[2][input.length()];
+ String out = "";
+ for(int i = 0; i<arr[0].length; i++) {
+ char inc = input.charAt(i), pc = key.charAt(i%key.length());
+ for(int x = 0; x<chars.length; x++) {
+ if(inc == chars[x])
+ arr[0][i] = x;
+ if(pc == chars[x])
+ arr[1][i] = x;
+ }
+ out += chars[(arr[0][i]+arr[1][i])%chars.length];
+ }
+ return out;
+ }
+
+ @Override
+ public String decode(String input) {
+ int[][] arr = new int[2][input.length()];
+ String out = "";
+ for(int i = 0; i<arr[0].length; i++) {
+ char inc = input.charAt(i), pc = key.charAt(i%key.length());
+ for(int x = 0; x<chars.length; x++) {
+ if(inc == chars[x])
+ arr[0][i] = x;
+ if(pc == chars[x])
+ arr[1][i] = x;
+ }
+ out += chars[((arr[0][i]-arr[1][i])+chars.length)%chars.length];
+ }
+ return out;
+ }
+
+}
diff --git a/src/algorithmus/XOR.java b/src/algorithmus/XOR.java
new file mode 100755
index 0000000..0bbfef3
--- /dev/null
+++ b/src/algorithmus/XOR.java
@@ -0,0 +1,102 @@
+package algorithmus;
+
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSpinner;
+
+public class XOR extends Algorithmus {
+
+ private String name, key;
+ private String[] folgen;
+ private char[] chars;
+
+ public XOR() {
+ name = "XOR";
+ key = "";
+ chars = new char[] { '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' };
+ folgen = new String[] { "01000001", "01000010", "01000011", "01000100", "01000101", "01000110", "01000111", "01001000", "01001001", "01001010", "01001011", "01001100", "01001101", "01001110", "01001111", "01010000", "01010001", "01010011", "01010100", "01010101", "01010110", "01010111", "01011000", "01011001", "01011010" };
+ }
+
+ @Override
+ public void options() {
+ JFrame frame = new JFrame();
+ frame.setLayout(null);
+ frame.setTitle("XOR");
+ frame.setSize(200, 150);
+ TextField keyField = new TextField();
+ keyField.setText(key);
+ keyField.setBounds(5, 5, 150, 20);
+ TextField alphabet = new TextField();
+ String alphaText = "";
+ for(int i = 0; i<chars.length; i++) {
+ alphaText += chars[i];
+ }
+ alphabet.setText(alphaText);
+ alphabet.setBounds(5, 30, 150, 20);
+ TextField binary = new TextField();
+ String binarystr = "";
+ for(int i = 0; i<folgen.length; i++) {
+ binarystr += folgen[i] + ";";
+ }
+ binary.setText(binarystr);
+ binary.setBounds(5, 55, 150, 20);
+ JButton apply = new JButton("Speichern");
+ apply.setBounds(5, 80, 100, 20);
+ apply.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String alpha = alphabet.getText();
+ chars = new char[alpha.length()];
+ for(int i = 0; i<chars.length; i++) {
+ chars[i] = alpha.charAt(i);
+ }
+ key = keyField.getText();
+ folgen = binary.getText().split(";");
+ }
+ });
+ frame.add(keyField);
+ frame.add(alphabet);
+ frame.add(binary);
+ frame.add(apply);
+ frame.setVisible(true);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String encode(String input) {
+ String out = "";
+ int size = input.length();
+ for(int i = 0; i<size; i++)
+ out += xor(folgen[Utils.inArr(chars, input.charAt(i))], folgen[Utils.inArr(chars, key.charAt(i%key.length()))]) + ';';
+ return out;
+ }
+
+ @Override
+ public String decode(String input) {
+ String out = "";
+ String[] in = input.split(";");
+ for(int i = 0; i<in.length; i++)
+ out += xor(in[i], folgen[Utils.inArr(chars, key.charAt(i%key.length()))]) + ';';
+ return out;
+ }
+
+ private String xor(String one, String two) {
+ String out = "";
+ for(int x = 0, len = one.length(); x<len; x++) {
+ if((one.charAt(x) == '0' && two.charAt(x) == '0') || (one.charAt(x) == '1' && two.charAt(x) == '1'))
+ out += '0';
+ else if((one.charAt(x) == '0' && two.charAt(x) == '1') || (one.charAt(x) == '1' && two.charAt(x) == '0'))
+ out += '1';
+ }
+ return out;
+ }
+
+}
diff --git a/src/algorithmus/Zaehlen.java b/src/algorithmus/Zaehlen.java
new file mode 100755
index 0000000..048377e
--- /dev/null
+++ b/src/algorithmus/Zaehlen.java
@@ -0,0 +1,55 @@
+package algorithmus;
+
+public class Zaehlen extends Algorithmus {
+
+ private String name = "Zaehlen";
+
+ @Override
+ public void options() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String encode(String input) {
+ input = input.toLowerCase();
+ int[][] arr = new int[2][26];
+ for(int x = 0; x<arr[0].length; x++) {
+ arr[0][x] = 97+x;
+ arr[1][x] = 0;
+ }
+ for(int i = 0, size = input.length(); i<size; i++)
+ for(int x = 0; x<arr[0].length; x++)
+ if((int)input.charAt(i) == arr[0][x])
+ arr[1][x]++;
+ String out = "";
+ for(int i = 0; i<arr[0].length; i++)
+ out += (char)arr[0][i] + ": " + arr[1][i] + "\n";
+ return out;
+ }
+
+ @Override
+ public String decode(String input) {
+ String[] arr = input.split(": ");
+ int[][] a = new int[2][26];
+ for(int x = 0; x<a[0].length; x++) {
+ a[0][x] = 97+x;
+ a[1][x] = 0;
+ }
+ for(int i = 0, x = 1; i<a[0].length; i++) {
+ a[1][i] = Integer.parseInt(arr[x].substring(0, arr[x].length()-2));
+ x++;
+ }
+ String out = "";
+ for(int i = 0; i<a[0].length; i++)
+ for(int x = 0; x<a[1][i]; x++)
+ out += (char)a[0][i];
+ return out.toUpperCase();
+ }
+
+}