So I've been trying to make this simple encryption program but I can't seem to figure out some things. The phrase I need to enter is
This is a very big morning.
When I enter it though it returns the string
This is a ag',rery dug>?/ijeb..w ssadorninjeb..w
Instead I return
This is a ajedg>P/..w',rery dg>P/ijedg>P/..w ssadorninjedg>P/..w
I don't understand why and how to fix it? I've been learning java for around a month now so I'm still fresh and if there's a similar question that's already been answered please link me there and I'll delete this post.
Here's the code:
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;
}
}