所以我需要使用此密码本进行加密和解密。
cijuskla .... t,有26个。所以c变成a,我变成b,j变成c ... t变成z。
我的大写字母设置相同。
突然出现在我脑海的第一件事就是,如果没有,
for(int i = 0; i < input.length(); i++) {
if input.charAt[i] == 'a' {
input.charAt[i] == 'c' }
else if input.charAt[i] ==
有什么更好的方法可以做到吗?
答案 0 :(得分:1)
我尝试过,代码如下。对代码的一些注释需要清楚理解:
//add all letters key value pair to this list
final HashMap<Character, Character> letterMapForDecrypt = new HashMap<>();
letterMapForDecrypt.put('c', 'a');
letterMapForDecrypt.put('d', 'b');
letterMapForDecrypt.put('f', 'k');
letterMapForDecrypt.put('h', 'j');
//adding reverse type of decrpyt letter list
final HashMap<Character, Character> letterMapForEncrypt = new HashMap<>();
letterMapForDecrypt.forEach((key, value) -> letterMapForEncrypt.put(value, key));
//decrpyte
String stringToDecrypt = "cddfh";
final char[] charsOfDecrpyt = stringToDecrypt.toCharArray();
for (int i = 0; i < charsOfDecrpyt.length; i++) {
//get value map and change this char
charsOfDecrpyt[i] = letterMapForDecrypt.get(charsOfDecrpyt[i]);
}
System.out.println(charsOfDecrpyt);
//encrpte
String stringToEncrypt = "cddfh";
final char[] charsOfEncrypt = stringToEncrypt.toCharArray();
for (int i = 0; i < charsOfEncrypt.length; i++) {
//get value map and change this char
charsOfDecrpyt[i] = letterMapForEncrypt.get(charsOfDecrpyt[i]);
}
System.out.println(charsOfEncrypt);
答案 1 :(得分:1)
您可以改用开关:
Dockerfile