package Day25;
import java.util.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
String str1 =sc.next();
char[] chin=str1.toCharArray();
char[] chout=new char[chin.length];
String str2 =sc.next();
char[] unchin=str2.toCharArray();
char[] unchout=new char[unchin.length];
Test test1=new Test();
test1.Encrypt(chin, chout);
Test test2=new Test();
test2.unEncrypt(unchout,unchin);//加密过程
}
public static void Encrypt(char[] aucPassword,char aucResult[])
{
for(int i=0;i<aucPassword.length;i++)
{
if(aucPassword[i]>='a'&&aucPassword[i]<'z')
{
aucPassword[i]=(char) (aucPassword[i]-31);
}
else if(aucPassword[i]=='z')
{
aucPassword[i]='A';
}else if(aucPassword[i]>='A'&&aucPassword[i]<'Z')
{
aucPassword[i]=(char) (aucPassword[i]+33);
}
else if(aucPassword[i]=='Z')
{
aucPassword[i]='a';
}
else if(aucPassword[i]>='0'&&aucPassword[i]<'9')
{
aucPassword[i]=(char) (aucPassword[i]+1);
}
else if(aucPassword[i]=='9')
{
aucPassword[i]='0';
}
}
for(int j=0;j<aucResult.length;j++)
{
aucResult[j]=aucPassword[j];
System.out.print(aucResult[j]);
}
System.out.println();
}
public static void unEncrypt(char[] result,char password[])//解密操作
{
for(int i=0;i<password.length;i++)
{
if(password[i]>'a'&&password[i]<='z')
{
password[i]=(char) (password[i]-33);
}
else if(password[i]=='a')
{
password[i]='Z';
}else if(password[i]>'A'&&password[i]<='Z')
{
password[i]=(char) (password[i]+31);
}
else if(password[i]=='A')
{
password[i]='z';
}
else if(password[i]>'0'&&password[i]<='9')
{
password[i]=(char) (password[i]-1);
}
else if(password[i]=='0')
{
password[i]='9';
}
}
for(int j=0;j<result.length;j++)
{
result[j]=password[j];
System.out.print(result[j]);
}
}
}
1、对输入的字符串进行加解密,并输出。
2加密方法为:
当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;
当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;
其他字符不做变化。
3、解密方法为加密的逆过程。