From c9dd9469183d95c6c2f4d01e3d6365ec57386a65 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:43:46 +0200 Subject: Initial commit --- src/algorithmus/Algorithmus.java | 13 +++++ src/algorithmus/Autokey.java | 103 ++++++++++++++++++++++++++++++++++ src/algorithmus/Blabla.java | 116 +++++++++++++++++++++++++++++++++++++++ src/algorithmus/Caesar.java | 96 ++++++++++++++++++++++++++++++++ src/algorithmus/Case.java | 81 +++++++++++++++++++++++++++ src/algorithmus/Constants.java | 13 +++++ src/algorithmus/Palisaden.java | 72 ++++++++++++++++++++++++ src/algorithmus/Utils.java | 39 +++++++++++++ src/algorithmus/Vigenere.java | 99 +++++++++++++++++++++++++++++++++ src/algorithmus/XOR.java | 102 ++++++++++++++++++++++++++++++++++ src/algorithmus/Zaehlen.java | 55 +++++++++++++++++++ 11 files changed, 789 insertions(+) create mode 100755 src/algorithmus/Algorithmus.java create mode 100755 src/algorithmus/Autokey.java create mode 100755 src/algorithmus/Blabla.java create mode 100755 src/algorithmus/Caesar.java create mode 100755 src/algorithmus/Case.java create mode 100755 src/algorithmus/Constants.java create mode 100755 src/algorithmus/Palisaden.java create mode 100755 src/algorithmus/Utils.java create mode 100755 src/algorithmus/Vigenere.java create mode 100755 src/algorithmus/XOR.java create mode 100755 src/algorithmus/Zaehlen.java (limited to 'src/algorithmus') 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=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 96 && ba[i] < 123) + ba[i] -= 32; + return ba; + } + + private byte[] lower(byte[] ba) { + for(int i = 0; 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