密码加密的问题

来源:互联网 发布:通达信 沪深日线数据 编辑:程序博客网 时间:2024/04/28 23:32

1.密码加密的问题

a.数字加5,不进位

b.字母如果是大写就转成小写,小写就转成大写

 

 

import java.util.*;
public class passWord
{
 public static void main(String [] args)
 {
  Scanner input=new Scanner(System.in);
  System.out.print("输入密码:");
  String pass=input.next();
//  for (int i=0;i<score.length;i++)
//  {
//   score[i]=pass.split('');
//  }
  System.out.println("刚才的密码是:");
  int[] num=new int[pass.length()];
  char [] c=new char[pass.length()];
  int [] numInt=new int [num.length];
  //存储加密后的数字
  int [] passLast=new int [num.length];
  String [] passTL=new String [num.length];
  
  for (int index=0;index<pass.length();index++)
  {
   //0-9  是48--57
   //a-z 是97-122
   //A-Z 是65-90
   c[index]=pass.charAt(index);
//   System.out.println(c[index]);
   num[index]=c[index];
  
  if (num[index]>=48&&num[index]<=57)
  {
   numInt[index]=num[index]-48;//还原为原来的数
   //System.out.println("转化为整数后是:");
   //是数字的话加5
   passLast[index]=numInt[index]+5;
   if (passLast[index]>=10)
   {
    passLast[index]=passLast[index]%10;
   }else
   {
    passLast[index]=passLast[index];
   }
   //System.out.println(numInt[index]);
   System.out.print(passLast[index]); 
  }
  //判断是不是字母--间隔为32
  if (num[index]>=65)
  {
   num[index]=c[index];
   if(num[index]>=65&&num[index]<=90)
   {
    num[index]=c[index]+32;
    //System.out.println("加密后的是qwewew:");
    //转换为小写
    passTL[index]=  (c[index]+" ").toLowerCase().trim(); 
   }else if(num[index]>=97&&num[index]<=120)
   {
    num[index]=c[index]-32;
    passTL[index]=(c[index]+" ").toUpperCase().trim();
   }
   System.out.print(passTL[index]);
   
  }
 
  }
  
  
 }

}

原创粉丝点击