字串加密
import java.util.Scanner;
class ShuJv
{
public String str,str2,str3;
int length,i,c2;
char c;
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++)
{
c=str.charAt(i);
if(c>64&&c<88)
{
c=(char)(c+3);
}
else if(c<91)
{
c=(char)(c-23);
}
else
{
System.out.println("输入错误,请重输");
get();
}
str2=str2+c;
}
}
public void set1()
{
System.out.println("加密后为"+str2);
}
public void set2()
{
str3="";
for(i=0;i<length;i++)
{
c=str2.charAt(i);
if(c>67&&c<=90)
{
c=(char)(c-3);
}
else if(c<=67)
{
c=(char)(c+23);
}
else
{
System.out.println("输入错误,请重输");
get();
}
str3=str3+c;
}
System.out.println("解密后为"+str3);
}
}
public class JiaMi
{
public static void main(String args[])
{
ShuJv s = new ShuJv();
s.get();
s.set1();
s.set2();
}
}