1、public class Cryptology char ciphertext;/密文 int key;char plaintext;/明文 StringBuffer plaintextStr;StringBuffer ciphertextStr;final int max=500;Cryptology()key=0;plaintextStr=new StringBuffer();ciphertextStr=new StringBuffer();int setKey()System.out.println(请输入一个 Caesar 密钥);Scanner sc=new Scanner(Syst
2、em.in);try key=sc.nextInt()%26;catch(Exception e)System.out.println(需要输入整数!);return key;void getPlaintext()/获得明文 plaintext=new charmax;for(int j=0;j=a&ch=A&ch=Z|ch=|ch=,|ch=.|ch=!)plaintexti=ch;i+;else System.out.println(输入不支持!break;try ch=(char)bf.read();catch(IOException e1)catch(IOException e)voi
3、d encryption()/加密 int temp=0;ciphertext=new charmax;jmax;j+)ciphertextj=;for(int i=0;i=a&plaintexti122)ciphertexti=(char)(97+temp-123);else ciphertexti=(char)temp;if(plaintexti=A&plaintexti90)ciphertexti=(char)(65+temp-91);ciphertextStr.append(ciphertexti);else break;void deciphering()/解密 char c=;in
4、t temp=0;i=97&ciphertexti=122)c=(char)(temp);if(temp=65&ciphertexti=90)c=(char)(temp);if(temp65)c=(char)(26+temp);plaintextStr.append(c);void display()System.out.println(密文明文对比);System.out.println(密文:+ciphertextStr);System.out.println(明文:+plaintextStr);主函数部分:public class Complication public static void main(String args)Cryptology cry=new Cryptology();cry.setKey();cry.getPlaintext();cry.encryption();cry.deciphering();cry.display();结果 1:结果 2: