diff options
Diffstat (limited to 'src/algorithmus')
-rwxr-xr-x | src/algorithmus/Algorithmus.java | 13 | ||||
-rwxr-xr-x | src/algorithmus/Autokey.java | 103 | ||||
-rwxr-xr-x | src/algorithmus/Blabla.java | 116 | ||||
-rwxr-xr-x | src/algorithmus/Caesar.java | 96 | ||||
-rwxr-xr-x | src/algorithmus/Case.java | 81 | ||||
-rwxr-xr-x | src/algorithmus/Constants.java | 13 | ||||
-rwxr-xr-x | src/algorithmus/Palisaden.java | 72 | ||||
-rwxr-xr-x | src/algorithmus/Utils.java | 39 | ||||
-rwxr-xr-x | src/algorithmus/Vigenere.java | 99 | ||||
-rwxr-xr-x | src/algorithmus/XOR.java | 102 | ||||
-rwxr-xr-x | src/algorithmus/Zaehlen.java | 55 |
11 files changed, 789 insertions, 0 deletions
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();
+ }
+
+}
|