-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.java
More file actions
111 lines (101 loc) · 5.8 KB
/
Copy pathDriver.java
File metadata and controls
111 lines (101 loc) · 5.8 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package project1;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean on = true;
while (on) {
System.out.println("\n\n\nProject\n\n1-Hillcipher\n2-Kasiski Test\n3-Break shift cipher\n4-Exit");
try {
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("1-Encrypt\n2-Decrypt\n3-Change key");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1: {
System.out.println("1-File\n2-System");
choice = sc.nextInt();
sc.nextLine();
int[][] key_matrix = HillCipher.slice_plain(FileOperatoins.read("Key.txt"), 3);
if (choice == 1) {
String encrypted = HillCipher.encrypt(FileOperatoins.read("Hill_plain.txt"), key_matrix);
System.out.println("Encrypted: " + encrypted);
FileOperatoins.write(encrypted, "Hill_cipher.txt");
} else {
System.out.print("Plain: ");
String plain = sc.nextLine();
System.out.println(plain);
String encrypted = HillCipher.encrypt(plain, key_matrix);
System.out.print("Encrypted: " + encrypted);
FileOperatoins.write(encrypted, "Hill_cipher.txt");
}
break;
}
case 2: {
System.out.println("1-File\n2-System");
choice = sc.nextInt();
sc.nextLine();
int[][] key_matrix = HillCipher.slice_plain(FileOperatoins.read("Key.txt"), 3);
if (choice == 1) {
String plain = HillCipher.decrypt(FileOperatoins.read("Hill_cipher.txt"), key_matrix);
System.out.println("plain: " + plain);
FileOperatoins.write(plain, "Hill_plain.txt");
} else {
System.out.print("Cipher: ");
String cipher = sc.nextLine();
String plain = HillCipher.decrypt(cipher, key_matrix);
System.out.println("Decrypted: " + plain);
FileOperatoins.write(plain, "Hill_plain.txt");
}
break;
}
case 3:
System.out.print("New Key: ");
String new_key = sc.nextLine();
if (new_key.length() != 9) {
System.out.println("3*3 Hillcipher key must be of length 9");
break;
}
FileOperatoins.write(new_key, "Key.txt");
break;
}
break;
case 2:
String plaintext =
"there are two ways of constructing a software design " +
"one way is to make it so simple that there are obviously no deficiencies " +
"and the other way is to make it so complicated that there are no obvious deficiencies " +
"the first method is far more difficult it demands the same skill devotion insight and " +
"even inspiration as the discovery of the simple physical laws which underlie the " +
"complex phenomena of nature cryptography is the practice and study of techniques " +
"for secure communication in the presence of third parties called adversaries " +
"more generally cryptography is about constructing and analyzing protocols that " +
"prevent third parties or the public from reading private messages";
String vigKey = "secret";
String ciphertext = VigenereCipher.encrypt(plaintext, vigKey);
System.out.println("Kasiski Test");
System.out.println("Original key : " + vigKey);
System.out.println("Ciphertext : " + ciphertext);
System.out.println();
String output = KasiskiTest.breakVigenere(ciphertext);
System.out.println(output);
FileOperatoins.write(output, "Kasiski Result");
break;
case 3:
System.out.print("Cipher to break: ");
String cipher = sc.nextLine();
System.out.println(ShiftCipherBreaker.breakCipher(cipher));
break;
case 4:
on = false;
break;
}
} catch (Exception e) {
System.out.println("Invalid input");
}
}
}
}