zoukankan      html  css  js  c++  java
  • 加密字符串

    //加密字符串
    
    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 +="
    
    解密后的字符串是:"+o;//定义输出格式
            
            JOptionPane.showMessageDialog(
                    null,"加密后的字符串是:"+output,"字符串"+s1,
                    JOptionPane.PLAIN_MESSAGE);
        
            
            System.exit(0);
            
        }
    
    	}
    

  • 相关阅读:
    组合与计数
    20160929训练记录
    奇特而有用的定理
    图论 500 题
    《长安十二时辰》愿你看尽世间百态,心中仍有热血
    洛谷 [P1337] 平衡点
    洛谷 [P3496] BLO
    洛谷 [P2341] 受欢迎的牛
    洛谷 [P3723] 礼物
    洛谷 [P3338] 力
  • 原文地址:https://www.cnblogs.com/1716467267-wang/p/4907253.html
Copyright © 2011-2022 走看看