标签:
//加密字符串 import javax.swing.JOptionPane; public class Jami { public static void main(String[] args) { String s1 = JOptionPane.showInputDialog("请输入字符串:"); String output; output = "字符串:"+s1; char[] c = new char[s1.length()]; s1.getChars(0, s1.length(), c,0); //加密 for(int i=0;i<s1.length();i++) { if(c[i]==‘X‘) c[i]=‘A‘; else if(c[i]==‘Y‘) c[i]=‘B‘; else if(c[i]==‘Z‘) c[i]=‘C‘; else if (c[i] == ‘ ‘) c[i]=c[i]; else c[i]+=3; } output=new String(c); //解密 char[] S2 = new char[s1.length()]; s1.getChars(0, s1.length(), S2,0); for(int i=0;i<s1.length();i++) { if(S2[i]==‘C‘) S2[i]=‘Z‘; else if(S2[i]==‘B‘) S2[i]=‘Y‘; else if(S2[i]==‘A‘) S2[i]=‘X‘; else if(S2[i] == ‘ ‘) S2[i]=S2[i]; else S2[i]-=3; } String o=new String(S2); output +="\n\n解密后的字符串是:"+o;//定义输出格式 JOptionPane.showMessageDialog( null,"加密后的字符串是:"+output,"字符串"+s1, JOptionPane.PLAIN_MESSAGE); System.exit(0); } }
标签:
原文地址:http://www.cnblogs.com/1716467267-wang/p/4907253.html