凯撒加密:
public static void main(String[] args) {
String input="hello world";
//向右移动
int key =3;
//转换字节数组
char[] chars=input.toCharArray();
//装密文
StringBuilder sb = new StringBuilder();
for (char c :chars ) {
int d=c;
d = d+key;
char newd= (char) d;
sb.append(newd);
}
System.out.println("密文:"+sb.toString());
//反转
StringBuilder bs = new StringBuilder();
String output =sb.toString();
char[] outchars=output.toCharArray();
for (char c : outchars) {
int d=c;
d= d-key;
char newd= (char) d;
bs.append(newd);
}
System.out.println("明文:" + bs.toString());
}
原文:https://www.cnblogs.com/money131/p/13192843.html