写一个加密和解密的method,还有用户输入的密钥,密钥 +就是顺着移动(如果+2,就是则字母A将变为C,字母B将变为D),- 就是倒着移动。
1 是加密
2 是解密
下面是给出的代码
import java.util.Scanner;
public class CaesarCypher {
// Write an encode method
// Write a decode method
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String message = "";
System.out.println("Do you have a message to (1) encode or (2) decode");
int option = in.nextInt();
in.nextLine();
if (option==1){
System.out.println("Type your message to encode");
message = in.nextLine();
}
if (option==2){
System.out.println("Type your message to decode");
message = in.nextLine();
}
}
}