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);
            
        }
    
    	}
    

  • 相关阅读:
    Orleans 2 实例
    Linux基础1 目录和文件系统
    C#中的异步多线程补充1
    委托的小例子(基本委托,匿名方法,lambda)
    Orleans 1 基本概念
    WPF10 Binding-2
    WPF9 Binding-1
    WPF8 UI布局
    WPF7 布局控件
    软工总结
  • 原文地址:https://www.cnblogs.com/1716467267-wang/p/4907253.html
Copyright © 2011-2022 走看看