summaryrefslogtreecommitdiff
path: root/src/algorithmus/Blabla.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/algorithmus/Blabla.java')
-rwxr-xr-xsrc/algorithmus/Blabla.java116
1 files changed, 116 insertions, 0 deletions
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;
+ }
+
+}