-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (45 loc) · 1.9 KB
/
Main.java
File metadata and controls
56 lines (45 loc) · 1.9 KB
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
46
47
48
49
50
51
52
53
54
55
56
import java.util.Arrays;
import javax.xml.bind.DatatypeConverter;
import java.util.Scanner;
/*
* The main runs some tests using IsEnglish, HexConverter, and
* SingleByteXorCipher objects
*/
public class Main {
public static void main(String args[]){
// construct objects
Scanner input = new Scanner(System.in);
HexConverter converter = new HexConverter();
SingleByteXorCipher singleCoder=new SingleByteXorCipher();
IsEnglish scorer = new IsEnglish();
//user input
System.out.println("Please enter a string to encrypt\n");
String message = input.nextLine();
//encrypt using key 0x50
String encrypted = singleCoder.SingleByteXorMaker(0x50, message);
//display message and encryption
System.out.printf("Message: %s, Score= %s \n", message,
scorer.scoreThatString(message));
System.out.printf("Encrypted: %s\n", encrypted);
//user chooses decrypt method
System.out.println("Please enter decrypt method" +
":1 for Frequency, 0 for Keyword?");
int method = input.nextInt();
//Frequency
if(method == 1){
System.out.println("Using frequency of English letters to " +
"determine the correct decrypted message");
String[] ans = singleCoder.BreakerFrequency(encrypted);
System.out.printf("Decoded String: %s \n Key: %s \n",
ans[0], ans[1]);
}
//Keywords
else{
System.out.println("Using common keywords in English to " +
"determine the correct decrypted message");
String[] ans = singleCoder.BreakerKeyWord(encrypted);
System.out.printf("Decoded String: %s \n Key: %s \n",
ans[0], ans[1]);
}
}
}