folder structure

This commit is contained in:
Daniel
2024-12-03 23:55:23 +02:00
parent 5aca7182ae
commit 6599f7ee43
6 changed files with 144 additions and 3 deletions

View File

@@ -0,0 +1,21 @@
package org.lumijiez.caesar;
import org.lumijiez.Utils;
public class DoubleCaesar {
public static String encode(int key, String keyWord, String content) {
StringBuilder encoded = new StringBuilder();
String fixedContent = content.replaceAll("\\s","");
Utils.ALPHABET = Utils.getDoubleCaesarAlphabet(Utils.toCaesarKey(keyWord));
for (char ch : fixedContent.toCharArray()) {
encoded.append(Utils.toNthLetter((Utils.getPos(ch) + key) % Utils.ALPHABET.length()));
}
Utils.returnAlphabet();
return encoded.toString();
}
}

View File

@@ -0,0 +1,35 @@
package org.lumijiez.caesar;
import org.lumijiez.Utils;
public class SimpleCaesar {
public static String encode(int key, String content) {
StringBuilder encoded = new StringBuilder();
String fixedContent = content.replaceAll("\\s","");
for (char ch : fixedContent.toCharArray()) {
encoded.append(Utils.toNthLetter((Utils.getPos(ch) + key) % Utils.ALPHABET.length()));
}
return encoded.toString();
}
public static String decode(int key, String content) {
StringBuilder decoded = new StringBuilder();
for (char ch : content.toCharArray()) {
int currentPosition = Utils.getPos(ch);
int newPosition = (currentPosition - key) % Utils.ALPHABET.length();
if (newPosition < 0) {
newPosition += Utils.ALPHABET.length();
}
decoded.append(Utils.toNthLetter(newPosition));
}
return decoded.toString();
}
}