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

    package zi; import java.util.Scanner;

    class Word {    

        public String str,str2,str3;    

         int length,i,a1;    

          char a;    

            Scanner scanner=new   

             Scanner(System.in);   

               public void get()    

              {    

                str2="";    

              System.out.println("请输入密码");    

              str=scanner.nextLine();      

                 length=str.length();    

                       for(i=0;i<length;i++)      

                       {      

                          a=str.charAt(i);      

                           if(a>64&&a<88)    

                             {      

                             a=(char)(a+3);    

                             }      

                           else if(a<91)    

                          {        

                         a=(char)(a-23);       

                          }       

                        else       

                            {        

                         System.out.println("输入有误 ,请重新输入");        

                      get();       }       

                    str2=str2+a;      

               }    

              }      

                        public void show()      

                          {       

                       System.out.println("加密后结果为"+str2);            

                         }     

                          public void show1()    

                            {        

                      str3="";        

                       for(i=0;i<length;i++)        

                             {        

                         a=str2.charAt(i);   

                       if(a>67&&a<=90)      

                         {           a=(char)(a-3);          }         

                       else if(a<=67)        

                        {           a=(char)(a+23);          }      

                           else    

                  {           System.out.println("输入有误 请重新输入");           get();          }         

              str3=str3+a;       

              }       

                System.out.println("解密后的结果为 "+str3);          

                   } }

        public class Password {

            public static void main(String args[]) {   

                Word b=new Word();   

                  b.get();

                  b.show();   

                   b.show1();

     }

    }

  • 相关阅读:
    HDU6301 SET集合的应用 贪心
    线段树与树状数组的对比应用
    树状数组
    JDBC链接MySQL数据库
    HDU4686Arc of Dream 矩阵快速幂
    HDU1757矩阵快速幂
    B1013. 数素数 (20)
    B1023. 组个最小数 (20)
    [教材]B1020. 月饼 (25)
    [教材]A1025. PAT Ranking (25)
  • 原文地址:https://www.cnblogs.com/wanghao369/p/4909837.html
Copyright © 2011-2022 走看看