diff options
author | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:43:46 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:43:46 +0200 |
commit | c9dd9469183d95c6c2f4d01e3d6365ec57386a65 (patch) | |
tree | 07ec933179eced02eec8a70f8b64c9281d453457 /src/algorithmus/Zaehlen.java |
Diffstat (limited to 'src/algorithmus/Zaehlen.java')
-rwxr-xr-x | src/algorithmus/Zaehlen.java | 55 |
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();
+ }
+
+}
|