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