blob: fb87354a156e2b98eb1e8163c3443057449e8058 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import java.util.*;
import java.io.*;
public class Client {
// TODO: Change this line once you've implemented a cipher!
public static final Cipher CHOSEN_CIPHER = null;
// (we also encourage you to change Cipher.MIN_CHAR and Cipher.MAX_CHAR when testing!)
public static void main(String[] args) throws FileNotFoundException {
Scanner console = new Scanner(System.in);
System.out.println("Welcome to the CSE 123 cryptography application!");
System.out.println("What would you like to do?");
int chosen = -1;
do {
System.out.println();
System.out.println("(1) Encode / (2) Decode a string");
System.out.println("(3) Encode / (4) Decode a file");
System.out.println("(5) Quit");
System.out.print("Enter your choice here: ");
chosen = Integer.parseInt(console.nextLine());
while (chosen < 1 || chosen > 5) {
System.out.print("Please enter a valid option from above: ");
chosen = Integer.parseInt(console.nextLine());
}
if (chosen == 1 || chosen == 2) {
System.out.println("Please enter the string you'd like to " +
(chosen == 1 ? "encode" : "decode") + ": ");
String input = console.nextLine();
System.out.println(chosen == 1 ? CHOSEN_CIPHER.encrypt(input) :
CHOSEN_CIPHER.decrypt(input));
} else if (chosen == 3 || chosen == 4) {
System.out.print("Please enter the name of the file you'd like to " +
(chosen == 3 ? "encode" : "decode") + ": ");
String fileName = console.nextLine();
if (chosen == 3) {
CHOSEN_CIPHER.encryptFile(fileName);
} else {
CHOSEN_CIPHER.decryptFile(fileName);
}
}
} while (chosen != 5);
}
}
|