|
@@ -1,4 +1,6 @@
|
1
|
1
|
import org.junit.Test;
|
|
2
|
+import java.io.File;
|
|
3
|
+import java.io.IOException;
|
2
|
4
|
|
3
|
5
|
import static org.junit.Assert.*;
|
4
|
6
|
|
|
@@ -12,8 +14,8 @@ public class ROT13Test {
|
12
|
14
|
String s2 = "ABCDEF";
|
13
|
15
|
|
14
|
16
|
// When
|
15
|
|
- ROT13 cipher = new ROT13();
|
16
|
|
- String actual = cipher.rotate(s1, 'A');
|
|
17
|
+ ROT13 cypher = new ROT13();
|
|
18
|
+ String actual = cypher.rotate(s1, 'A');
|
17
|
19
|
|
18
|
20
|
// Then
|
19
|
21
|
assertTrue(actual.equals(s2));
|
|
@@ -26,8 +28,8 @@ public class ROT13Test {
|
26
|
28
|
String s2 = "DEFABC";
|
27
|
29
|
|
28
|
30
|
// When
|
29
|
|
- ROT13 cipher = new ROT13();
|
30
|
|
- String actual = cipher.rotate(s1, 'D');
|
|
31
|
+ ROT13 cypher = new ROT13();
|
|
32
|
+ String actual = cypher.rotate(s1, 'D');
|
31
|
33
|
|
32
|
34
|
// Then
|
33
|
35
|
assertTrue(actual.equals(s2));
|
|
@@ -40,8 +42,8 @@ public class ROT13Test {
|
40
|
42
|
String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM";
|
41
|
43
|
|
42
|
44
|
// When
|
43
|
|
- ROT13 cipher = new ROT13();
|
44
|
|
- String actual = cipher.rotate(s1, 'N');
|
|
45
|
+ ROT13 cypher = new ROT13();
|
|
46
|
+ String actual = cypher.rotate(s1, 'N');
|
45
|
47
|
System.out.println(s1);
|
46
|
48
|
System.out.println(actual);
|
47
|
49
|
// Then
|
|
@@ -51,7 +53,7 @@ public class ROT13Test {
|
51
|
53
|
@Test
|
52
|
54
|
public void cryptTest1() {
|
53
|
55
|
// Given
|
54
|
|
- ROT13 cipher = new ROT13('a', 'n');
|
|
56
|
+ ROT13 cypher = new ROT13('a', 'n');
|
55
|
57
|
|
56
|
58
|
String Q1 = "Why did the chicken cross the road?";
|
57
|
59
|
String A1 = "Jul qvq gur puvpxra pebff gur ebnq?";
|
|
@@ -60,14 +62,14 @@ public class ROT13Test {
|
60
|
62
|
String A2 = "To get to the other side!";
|
61
|
63
|
|
62
|
64
|
// When
|
63
|
|
- String actual = cipher.encrypt(Q1);
|
|
65
|
+ String actual = cypher.encrypt(Q1);
|
64
|
66
|
System.out.println(Q1);
|
65
|
67
|
System.out.println(A1);
|
66
|
68
|
// Then
|
67
|
69
|
assertTrue(actual.equals(A1));
|
68
|
70
|
|
69
|
71
|
// When
|
70
|
|
- String actual2 = cipher.decrypt(Q2);
|
|
72
|
+ String actual2 = cypher.decrypt(Q2);
|
71
|
73
|
System.out.println(Q2);
|
72
|
74
|
System.out.println(A2);
|
73
|
75
|
// Then
|
|
@@ -76,16 +78,38 @@ public class ROT13Test {
|
76
|
78
|
@Test
|
77
|
79
|
public void cryptTest2() {
|
78
|
80
|
// Given
|
79
|
|
- ROT13 cipher = new ROT13('a', 'n');
|
|
81
|
+ ROT13 cypher = new ROT13('a', 'n');
|
80
|
82
|
|
81
|
83
|
String Q1 = "Why did the chicken cross the road?";
|
82
|
84
|
System.out.println(Q1);
|
83
|
85
|
|
84
|
86
|
// When
|
85
|
|
- String actual = cipher.crypt(cipher.crypt(Q1));
|
|
87
|
+ String actual = cypher.crypt(cypher.crypt(Q1));
|
86
|
88
|
System.out.println(actual);
|
87
|
89
|
// Then
|
88
|
90
|
assertTrue(actual.equals(Q1));
|
89
|
91
|
}
|
90
|
92
|
|
|
93
|
+ @Test
|
|
94
|
+ public void hideNewFile() throws IOException {
|
|
95
|
+ //Given
|
|
96
|
+ ROT13 cypher = new ROT13();
|
|
97
|
+ String filePath = "/Users/ben/Labs/ZCW-SimpleCrypt0/sonnet18.txt";
|
|
98
|
+
|
|
99
|
+ File newFile = cypher.newFile(filePath, "sonnet18.enc");
|
|
100
|
+ String encryptedFile = cypher.fileString(newFile);
|
|
101
|
+ assertTrue(newFile.exists());
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ @Test
|
|
105
|
+ public void decryptNewFile() throws IOException {
|
|
106
|
+ ROT13 cypher = new ROT13();
|
|
107
|
+
|
|
108
|
+ String filePath = "/Users/ben/Labs/ZCW-SimpleCrypt0/sonnet18.enc";
|
|
109
|
+
|
|
110
|
+ File newFile = cypher.newFile(filePath, "sonnet18.dcr");
|
|
111
|
+ String encryptedFile = cypher.fileString(newFile);
|
|
112
|
+ assertTrue(newFile.exists());
|
|
113
|
+ }
|
|
114
|
+
|
91
|
115
|
}
|