public class Caesar {
//利用凯撒密码对输入的字母加密后出一个加密后的字母
public static String table = "abcdefghifjmnlqpqrstuvwxyz";
public static char cipher(char str){
int position = (table.indexOf(str)+3)%26;
System.out.print(position+":");
return table.charAt(position);
}
public static void main(String args[]){
//key:219 ,palin:chenzhen
String plain = "chenzhen";
System.out.print("明文为:"+plain);
char []data = plain.toCharArray();
for(int i=0;i<data.length;i++){
data[i]=cipher(data[i]);
}
System.out.println("加密后为:"+new String(data));
}
}
//利用凯撒密码对输入的字母加密后出一个加密后的字母
public static String table = "abcdefghifjmnlqpqrstuvwxyz";
public static char cipher(char str){
int position = (table.indexOf(str)+3)%26;
System.out.print(position+":");
return table.charAt(position);
}
public static void main(String args[]){
//key:219 ,palin:chenzhen
String plain = "chenzhen";
System.out.print("明文为:"+plain);
char []data = plain.toCharArray();
for(int i=0;i<data.length;i++){
data[i]=cipher(data[i]);
}
System.out.println("加密后为:"+new String(data));
}
}