所以我一直在尝试制作这个简单的加密程序,但我似乎无法弄清楚一些事情。我需要输入的短语是
This is a very big morning.
当我输入它虽然它返回字符串
This is a ag',rery dug>?/ijeb..w ssadorninjeb..w
相反,我回来了
This is a ajedg>P/..w',rery dg>P/ijedg>P/..w ssadorninjedg>P/..w
我不明白为什么以及如何解决它?我已经学习 java 大约一个月了,所以我还很新鲜,如果有类似的问题已经得到解答,请在此处链接我,我将删除此帖子。
这是代码:
import static java.lang.System.out;
import java.util.Scanner;
class Encryption {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Crypto user1 = new Crypto();
out.print("Please enter in a sentence: ");
String user = userInput.nextLine();
user1.encrypt(user);
out.print(user1.getEncrypt());
}
}
public Crypto() { }
public String myEn;
public void encrypt(String Sentence) {
myEn = Sentence.replaceAll("v","ag',r")
.replaceAll("m" , "ssad")
.replaceAll("g" , "jeb..w")
.replaceAll("b" , "dg>P/");
}
public String getEncrypt() {
return myEn;
}
}