|
@@ -10,23 +10,57 @@ public class ROT13 {
|
10
|
10
|
ROT13() {
|
11
|
11
|
}
|
12
|
12
|
|
|
13
|
+// public String shift13(String str, Character ch) {
|
|
14
|
+// StringBuilder shifted = new StringBuilder();
|
|
15
|
+// Character[] strToArray = new Character[0];
|
|
16
|
+// for (int i = 0; i < strToArray.length; i++) {
|
|
17
|
+// if (i >= 97 && i <= 122) {
|
|
18
|
+// i += 13;
|
|
19
|
+// shifted.append(i);
|
|
20
|
+// }
|
|
21
|
+// if (i <= 90 && i >= 65) {
|
|
22
|
+// i += 13;
|
|
23
|
+// shifted.append(i);
|
|
24
|
+// } else {
|
|
25
|
+// shifted.append(i);
|
|
26
|
+// }
|
|
27
|
+// }
|
|
28
|
+// return shifted.toString();
|
|
29
|
+// }
|
13
|
30
|
|
14
|
|
- public String crypt(String text) throws UnsupportedOperationException {
|
15
|
31
|
|
16
|
|
- return "";
|
|
32
|
+ public String crypt(String text) throws UnsupportedOperationException {
|
|
33
|
+ StringBuilder sb = new StringBuilder();
|
|
34
|
+ for (int i = 0; i < text.length(); i++) {
|
|
35
|
+ char c= text.charAt(i);
|
|
36
|
+ if (c >= 'a' && c <= 'm') {
|
|
37
|
+ c += 13;
|
|
38
|
+ } else if (c >= 'A' && c <= 'M') {
|
|
39
|
+ c += 13;
|
|
40
|
+ } else if (c >= 'n' && c <= 'z') {
|
|
41
|
+ c -= 13;
|
|
42
|
+ } else if (c >= 'N' && c <= 'Z') {
|
|
43
|
+ c -= 13;
|
|
44
|
+ }
|
|
45
|
+ sb.append(c);
|
|
46
|
+ }
|
|
47
|
+ return sb.toString();
|
17
|
48
|
}
|
18
|
49
|
|
19
|
|
- public String encrypt(String text) {
|
20
|
|
- return text;
|
|
50
|
+ public String encrypt (String text){
|
|
51
|
+ return crypt(text);
|
21
|
52
|
}
|
22
|
53
|
|
23
|
|
- public String decrypt(String text) {
|
24
|
|
- return text;
|
|
54
|
+ public String decrypt (String text){
|
|
55
|
+ return crypt(text);
|
25
|
56
|
}
|
26
|
57
|
|
27
|
|
- public static String rotate(String s, Character c) {
|
28
|
|
-
|
29
|
|
- return "";
|
|
58
|
+ public static String rotate (String s, Character c){
|
|
59
|
+ int startIndex = s.indexOf(c);
|
|
60
|
+ StringBuilder sb = new StringBuilder();
|
|
61
|
+ sb.append(s.substring(startIndex, s.length()));
|
|
62
|
+ sb.append(s.substring(0, startIndex));
|
|
63
|
+ return sb.toString();
|
30
|
64
|
}
|
31
|
65
|
|
32
|
66
|
}
|