|
|
@@ -1,32 +1,52 @@
|
|
1
|
|
-import static java.lang.Character.isLowerCase;
|
|
2
|
|
-import static java.lang.Character.isUpperCase;
|
|
3
|
|
-import static java.lang.Character.toLowerCase;
|
|
4
|
|
-
|
|
5
|
|
-public class ROT13 {
|
|
|
1
|
+public class ROT13 {
|
|
|
2
|
+ private int shift;
|
|
6
|
3
|
|
|
7
|
4
|
ROT13(Character cs, Character cf) {
|
|
|
5
|
+ this.shift = cs - cf;
|
|
8
|
6
|
}
|
|
9
|
7
|
|
|
10
|
8
|
ROT13() {
|
|
|
9
|
+ this.shift = 13;
|
|
11
|
10
|
}
|
|
12
|
|
-
|
|
13
|
|
-
|
|
14
|
|
- public String crypt(String text) throws UnsupportedOperationException {
|
|
15
|
|
-
|
|
16
|
|
- return "";
|
|
|
11
|
+ /* * ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the ROT13 class
|
|
|
12
|
+ * crypt("Why did the chicken cross the road?") should produce
|
|
|
13
|
+ "Jul qvq gur puvpxra pebff gur ebnq?"
|
|
|
14
|
+ * crypt("Gb trg gb gur bgure fvqr!") should produce "To get to the other side!"
|
|
|
15
|
+ * Make a constructor that takes two arguments to set the cipher correspondence. `ROT13 superSecure = new ROT13("a","m");`
|
|
|
16
|
+ * this defines the SHIFT of the two Character arrays.
|
|
|
17
|
+ * Caesar - make a subclass of ROT13 that implements the famous caesar cipher.
|
|
|
18
|
+ * Create you own cipher, using a different set of */
|
|
|
19
|
+
|
|
|
20
|
+ public String crypt(String text) throws UnsupportedOperationException {
|
|
|
21
|
+ StringBuilder builder = new StringBuilder();
|
|
|
22
|
+ char[] chars = text.toCharArray();
|
|
|
23
|
+ for (int i = 0; i < chars.length; i++) {
|
|
|
24
|
+ char c = text.charAt(i);
|
|
|
25
|
+ if (c >= 'a' && c <= 'm') {
|
|
|
26
|
+ c += 13;
|
|
|
27
|
+ } else if (c >= 'A' && c <= 'M') {
|
|
|
28
|
+ c += 13;
|
|
|
29
|
+ } else if (c >= 'n' && c <= 'z') {
|
|
|
30
|
+ c -= 13;
|
|
|
31
|
+ } else if (c >= 'N' && c <= 'Z') {
|
|
|
32
|
+ c -= 13;
|
|
|
33
|
+ }
|
|
|
34
|
+ builder.append(c);
|
|
|
35
|
+ }
|
|
|
36
|
+ return builder.toString();
|
|
17
|
37
|
}
|
|
18
|
38
|
|
|
19
|
39
|
public String encrypt(String text) {
|
|
20
|
|
- return text;
|
|
|
40
|
+ return crypt(text);
|
|
21
|
41
|
}
|
|
22
|
42
|
|
|
23
|
43
|
public String decrypt(String text) {
|
|
24
|
|
- return text;
|
|
|
44
|
+ return crypt(text);
|
|
25
|
45
|
}
|
|
26
|
46
|
|
|
27
|
47
|
public static String rotate(String s, Character c) {
|
|
28
|
|
-
|
|
29
|
|
- return "";
|
|
|
48
|
+ String sub = s.substring(0, s.indexOf(c));
|
|
|
49
|
+ String sub1 = s.substring(s.indexOf(c));
|
|
|
50
|
+ return sub1.concat(sub);
|
|
30
|
51
|
}
|
|
31
|
|
-
|
|
32
|
52
|
}
|