uebungen/sources/beispieleVL/Crypter/CrypterImpl.java

66 lines
1.8 KiB
Java
Raw Normal View History

package Crypter;
2023-04-27 21:55:09 +02:00
import java.util.HashMap;
/**
* Implementierung des Crypter-Interfaces.
*/
public class CrypterImpl implements Crypter {
private HashMap<String, String> clear = new HashMap<String, String>();
public CrypterImpl() {
for (int i = 0; i < CLEAR_ALPHABET.length(); i++) {
String zw2 = CYPHER_ALPHABET.charAt(i) + "";
String zw1 = CLEAR_ALPHABET.charAt(i) + "";
clear.put(zw1, zw2);
}
}
@Override
public String encrypt(String input) {
if (input.equals(null)) {
return null;
} else {
input = input.toLowerCase();
String result = "";
for (int i = 0; i < input.length(); i++) {
if (clear.containsKey(input.charAt(i) + "")) {
result += clear.get(input.charAt(i) + "");
} else if (input.charAt(i) == '!'
|| input.charAt(i) == '('
|| input.charAt(i) == ')'
|| input.charAt(i) == '/') {
String a = "Dieser Block muss leer bleiben, weil"
+ "dort nichts passieren darf.";
} else {
result += input.charAt(i) + "";
}
}
return result;
}
}
@Override
public String decrypt(String input) {
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == '!'
|| input.charAt(i) == 'Ü'
|| input.charAt(i) == 'Ä'
|| input.charAt(i) == 'Ö'
|| input.charAt(i) == '/'
|| input.charAt(i) == '&'
|| input.charAt(i) == 'X') {
return null;
}
}
return encrypt(input);
}
}