import java.util.*;
public class Decrption {//解密类
Scanner input=new Scanner(System.in);
public String joinString(char[] zm){
Switcher diao=new Switcher();
char[] splitString2=new char[40];
String reString2="";
System.out.print("请输入加密后的字符串:");
String houString=input.next();
if(houString.equals(diao.reString)){
for(int i=0;i<houString.length();i++){
splitString2[i]=houString.charAt(i);
}
for(int i=0;i<houString.length();i++){
for(int j=3;j<zm.length;j++){
if(splitString2[i]=='a'){
splitString2[i]='x';
break;
}
if(splitString2[i]=='b'){
splitString2[i]='y';
break;
}
if(splitString2[i]=='c'){
splitString2[i]='z';
break;
}
if(splitString2[i]==zm[j]){
splitString2[i]=zm[j-3];
break;
}
if(j==zm.length-1){
splitString2[i]=splitString2[i];
}
}
}
for(int i=0;i<houString.length();i++){
reString2=reString2+splitString2[i];
}
}
return reString2;
}
}
import java.util.*;
public class Switcher {//测试类
/**
* @param args
*/
Scanner input=new Scanner(System.in);
String reString;
public static void main(String[] args) {
// TODO Auto-generated method stub
//Encryption me1=new Encryption();
Switcher method1=new Switcher();
method1.showmenu();
}
public void showmenu(){
Encrption me1=new Encrption();
Decrption me2=new Decrption();
char[] ziMu1={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c'};
char[] ziMu2={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
System.out.println("******欢迎使用凯撒加密器****");
System.out.println("***1.加密 2.解密 3.退出***");
System.out.println("***************************");
System.out.print("请选择菜单:");
int choice=input.nextInt();
if(choice==1){
reString=me1.addMi(ziMu1);
System.out.println("加密后的字符串是:"+reString);
System.out.println("\n");
showmenu();
}
else if(choice==2){
String que=me2.joinString(ziMu2);
if(que!=""){
System.out.println("解密后的字符串是:"+que);
showmenu();
}
else{
System.out.println("该字符串未被加密操作");
showmenu();
}
}
else if(choice==3){
exit();
}
}
public void exit(){
System.out.println("谢谢使用!!!");
}
}
import java.util.*;
public class Encrption {//加密类
public String addMi(char[] zm){
Scanner input=new Scanner(System.in);
System.out.print("请输入待加密的字符串:");
String yuanString=input.next();
char[] splitString1=new char[40];
for(int i=0;i<yuanString.length();i++){
splitString1[i]=yuanString.charAt(i);
}
for(int i=0;i<yuanString.length();i++){
for(int j=0;j<zm.length;j++){
if(splitString1[i]==(zm[j])){
splitString1[i]=zm[j+3];
break;
}
if(j==zm.length-1){
splitString1[i]=splitString1[i];
}
}
}
String joinString="";
for(int i=0;i<yuanString.length();i++){