|
@@ -1,8 +1,14 @@
|
|
1
|
+import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
|
|
2
|
+
|
1
|
3
|
import static java.lang.Character.isLowerCase;
|
2
|
4
|
import static java.lang.Character.isUpperCase;
|
3
|
5
|
import static java.lang.Character.toLowerCase;
|
4
|
6
|
|
5
|
|
-public class ROT13 {
|
|
7
|
+public class ROT13 {
|
|
8
|
+
|
|
9
|
+ protected String alphaUp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
10
|
+ protected String alphaLow = "abcdefghijklmnopqrstuvwxyz";
|
|
11
|
+
|
6
|
12
|
|
7
|
13
|
ROT13(Character cs, Character cf) {
|
8
|
14
|
}
|
|
@@ -12,21 +18,58 @@ public class ROT13 {
|
12
|
18
|
|
13
|
19
|
|
14
|
20
|
public String crypt(String text) throws UnsupportedOperationException {
|
|
21
|
+ StringBuilder simple = new StringBuilder();
|
|
22
|
+ for (int x = 0; x < text.length(); x++) {
|
|
23
|
+ char letter = text.charAt(x);
|
|
24
|
+ if (letter >= 'A' && letter <= 'M')
|
|
25
|
+ simple.append(letter += 13);
|
|
26
|
+ else if (letter >= 'N' && letter <= 'Z')
|
|
27
|
+ simple.append(letter -= 13);
|
|
28
|
+ else if (letter >= 'a' && letter <= 'm')
|
|
29
|
+ simple.append(letter += 13);
|
|
30
|
+ else if (letter >= 'n' && letter <= 'z')
|
|
31
|
+ simple.append(letter -= 13);
|
|
32
|
+ else
|
|
33
|
+ simple.append(letter);
|
|
34
|
+ }
|
15
|
35
|
|
16
|
|
- return "";
|
|
36
|
+ return simple.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
|
|
- public static String rotate(String s, Character c) {
|
28
|
47
|
|
29
|
|
- return "";
|
|
48
|
+ public static String rotate(String s, Character c) {
|
|
49
|
+ StringBuilder rotated = new StringBuilder();
|
|
50
|
+ int startIndex = s.indexOf(c);
|
|
51
|
+ rotated.append(s.substring(startIndex, s.length()));
|
|
52
|
+ rotated.append(s.substring(0, startIndex));
|
|
53
|
+ return rotated.toString();
|
30
|
54
|
}
|
31
|
55
|
|
32
|
|
-}
|
|
56
|
+ public String createCipher(String upper, Character chooseUp, String lower, Character chooseLow, String input) {
|
|
57
|
+ String rotateUp = rotate(alphaUp, D);
|
|
58
|
+ String rotateLow = rotate(alphaLow, d);
|
|
59
|
+
|
|
60
|
+ StringBuilder ciphered = new StringBuilder();
|
|
61
|
+ for (int x = 0; x < input.length(); i++) {
|
|
62
|
+ char letter = input.charAt(0);
|
|
63
|
+ if (letter >= 'A' && letter <= 'Z')
|
|
64
|
+ ciphered.append(rotateUp.indexOf(letter));
|
|
65
|
+ else if (letter >= 'a' && letter <= 'z')
|
|
66
|
+ ciphered.append(rotateLow.indexOf(letter));
|
|
67
|
+ else return letter;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ return ciphered.toString();
|
|
73
|
+
|
|
74
|
+ }
|
|
75
|
+}
|