I'm taking my first programming class, and we're using java. I've been getting the hang of everything so far, but functions are starting to leave me in the dust I think. I'm currently working on a project that is supposed to encrypt or decrypt a phrase, and I'm stuck.
I'm not sure how to convert a phrase the user inputs from the 'key' string (correct alphabet) to my 'alpha' string (jumbled alphabet). Can anyone help me out?
Here is the program so far:
Code:
import java.util.*;
public class Crypto {
static Scanner input = new Scanner(System.in);
static String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static String key = "UBWKOVGAPRFJLCQHZENSXDMYTI";
public static void main(String[] args) {
boolean keepGoing = true;
while(keepGoing){
String response = menu();
if (response.equals("1")){
System.out.println("Please enter unencrypted phrase");
String plain = input.nextLine();
plain = plain.toUpperCase();
System.out.println(encrypt(plain));
} else if (response.equals("2")){
System.out.println("Please enter encrypted phrase");
String code = input.nextLine();
code = code.toUpperCase();
System.out.println(decrypt(code));
} else if (response.equals("0")){
System.out.println("Goodbye!");
keepGoing = false;
} else {
System.out.println("Sorry. I didn't understand");
} // end if
} // end while
} // end main
public static String menu(){
System.out.println("Crypto Machine");
System.out.println("");
System.out.println("Please enter a selection.");
System.out.println("0) Quit");
System.out.println("1) Encrypt a phrase.");
System.out.println("2) Decrypt a phrase.");
String result = input.nextLine();
return result;
} //end menu
public static String decrypt(){
} //end decrypt
public static String encrypt(){
} //end encrypt
} // end Crypto