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

  • 相关阅读:
    stm32启动代码分析
    STM32固件库详解
    ARM GCC CodeSourcery EABI下载地址
    Linux/redhat 基本网络配置
    侧边栏导航
    div滚动,页面不滚动
    自定义滚动条样式
    placeholder自定义CSS
    浏览器判断
    初始化页面垂直居中
  • 原文地址:https://www.cnblogs.com/1716467267-wang/p/4907253.html
Copyright © 2011-2022 走看看