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/Core.java | 8 +++ src/Mainframe.java | 78 ++++++++++++++++++++++++++ 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 +++++++++++++++++++ 13 files changed, 875 insertions(+) create mode 100755 src/Core.java create mode 100755 src/Mainframe.java 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') 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=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