-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTester.java
174 lines (157 loc) · 5.99 KB
/
Tester.java
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package assignment1;
public class Tester {
public static void main(String[] args) {
//Testing makeValid
String originalMessage = "It's been snowing, now there's ice everywhere.";
Message M1 = new Message(originalMessage);
if (M1.equals(new Message("itsbeensnowingnowtheresiceeverywhere"))){
System.out.println("makeValid seems correct.");
}
else{
System.out.println("makeValid is incorrect.");
}
//Testing Caesar cipher
originalMessage = "Are you going to get the first one ?";
M1 = new Message(originalMessage);
int key1 = 5;
M1.caesarCipher(key1);
if (M1.equals(new Message ("fwjdtzltnslytljyymjknwxytsj"))){
System.out.println("Caesar cipher seems correct.");
}
else{
System.out.println("Caesar cipher is incorrect.");
}
//Testing Caesar decipher
M1 = new Message ("fwjdtzltnslytljyymjknwxytsj");
M1.caesarDecipher(key1);
if (M1.equals(new Message (originalMessage))){
System.out.println("You paid attention to the range of caesarCipher");
}
else{
System.out.println("the range of caesarCipher is wider than what you coded");
}
//Testing Caesar analysis
originalMessage = "Attenborough is widely considered a national treasure in Britain, although he himself does not like the term.[6][7][8] In 2002 he was named among the 100 Greatest Britons following a UK-wide poll for the BBC.[9] He is the younger brother of the late director, producer and actor Richard Attenborough,[10] and older brother of the late motor executive John Attenborough.";
String codedMessage = "fyyjsgtwtzlmnxbnijqdhtsxnijwjifsfyntsfqywjfxzwjnsgwnyfnsfqymtzlmmjmnrxjqkitjxstyqnpjymjyjwrnsmjbfxsfrjifrtslymjlwjfyjxygwnytsxktqqtbnslfzpbnijutqqktwymjgghmjnxymjdtzsljwgwtymjwtkymjqfyjinwjhytwuwtizhjwfsifhytwwnhmfwifyyjsgtwtzlmfsitqijwgwtymjwtkymjqfyjrtytwjcjhzynajotmsfyyjsgtwtzlm" ;
Message M2 = new Message(codedMessage);
M2.caesarAnalysis();
if (M2.equals(new Message (originalMessage))){
System.out.println("Caesar analysis seems correct.");
}
else{
System.out.println("Caesar analysis is incorrect.");
}
//Testing Vigenere Cipher
originalMessage = "Harder now : go for the Vigenere cipher";
Message M3 = new Message(originalMessage);
int[] key3 = {1,2,1,0};
M3.vigenereCipher(key3);
if (M3.equals(new Message("icsdftooxipfptuhfxjgfpfrfejpigs"))){
System.out.println("Vigenere cipher seems correct.");
}
else{
System.out.println("Vigenere cipher is incorrect.");
}
//Testing Vigenere Decipher
M3 = new Message("icsdftooxipfptuhfxjgfpfrfejpigs");
M3.vigenereDecipher(key3);
if (M3.equals(new Message(originalMessage))){
System.out.println("Vigenere decipher seems correct.");
}
else{
System.out.println("Vigenere decipher is incorrect.");
}
//Testing transposition cipher
originalMessage = "Last one to code and you are good for this assignment !! :)";
Message M4 = new Message(originalMessage);
int key4 = 6;
M4.transpositionCipher(key4);
if (M4.equals(new Message ("leeuohitataadig*sonrfsn*tcdeoam*ooygrse*ndootsn*", false))){
System.out.println("Transposition cipher seems correct.");
}
else{
System.out.println("Transposition cipher is incorrect.");
}
//Testing transposition decipher
M4 = new Message("leeuohitataadig*sonrfsn*tcdeoam*ooygrse*ndootsn*", false);
M4.transpositionDecipher(key4);
if (M4.equals(new Message(originalMessage))){
System.out.println("Transposition decipher seems correct.");
}
else{
System.out.println("Transposition decipher is incorrect.");
}
//new tests
//Testing transposition cipher
originalMessage = "Last one to code and you are good for this assignmen !! :)";
Message M5 = new Message(originalMessage);
int key5 = 7;
M5.transpositionCipher(key5);
if (M5.equals(new Message ("ltnersaodgtiscyohgtoooinodudsmneafaeearosn", false))){
System.out.println("Transposition cipher seems correct.");
}
else{
System.out.println("Transposition cipher is incorrect.");
}
//Testing transposition decipher
M5 = new Message("ltnersaodgtiscyohgtoooinodudsmneafaeearosn", false);
M5.transpositionDecipher(key5);
if (M5.equals(new Message(originalMessage))){
System.out.println("Transposition decipher seems correct.");
}
else{
System.out.println("Transposition decipher is incorrect.");
}
//Testing Caesar cipher
originalMessage = "Are you going to get the first one ?";
M1 = new Message(originalMessage);
int key6 = -60;
M1.caesarCipher(key6);
if (M1.equals(new Message ("sjwqgmygafylgywllzwxajklgfw"))){
System.out.println("Caesar cipher seems correct.");
}
else{
System.out.println("Caesar cipher is incorrect.");
}
//Testing Caesar decipher
M1 = new Message ("sjwqgmygafylgywllzwxajklgfw");
M1.caesarDecipher(key6);
if (M1.equals(new Message (originalMessage))){
System.out.println("You paid attention to the range of caesarCipher");
}
else{
System.out.println("the range of caesarCipher is wider than what you coded");
}
//Testing Caesar analysis
originalMessage = "reeeeeeencidefuwoyizhuirukanbujianzuideguodu";
codedMessage = "qdddddddmbhcdetvnxhygthqtjzmatihzmythcdftnct";
Message M7 = new Message(codedMessage);
M7.caesarAnalysis();
if (M7.equals(new Message (originalMessage))){
System.out.println("Caesar analysis seems correct.");
}
else{
System.out.println("Caesar analysis is incorrect.");
}
//Testing Vigenere Cipher
originalMessage = "Harder now : go for the Vigenere cipher";
Message M8 = new Message(originalMessage);
int[] key8 = {15,17,4,25,21,11,3};
M8.vigenereCipher(key8);
if (M8.equals(new Message("wrvczcqdnknazuiyiudrhcvvdxtswvv"))){
System.out.println("Vigenere cipher seems correct.");
}
else{
System.out.println("Vigenere cipher is incorrect.");
}
//Testing Vigenere Decipher
M8 = new Message("wrvczcqdnknazuiyiudrhcvvdxtswvv");
M8.vigenereDecipher(key8);
if (M8.equals(new Message(originalMessage))){
System.out.println("Vigenere decipher seems correct.");
}
else{
System.out.println("Vigenere decipher is incorrect.");
}
}
}