|
@@ -1,3 +1,5 @@
|
|
1
|
+package src;
|
|
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;
|
|
@@ -12,21 +14,32 @@ public class ROT13 {
|
12
|
14
|
|
13
|
15
|
|
14
|
16
|
public String crypt(String text) throws UnsupportedOperationException {
|
15
|
|
-
|
16
|
|
- return "";
|
|
17
|
+ StringBuilder sb = new StringBuilder();
|
|
18
|
+ for (int i = 0; i < text.length(); i++) {
|
|
19
|
+ char c = text.charAt(i);
|
|
20
|
+ if (c >= 'a' && c <= 'm') c += 13;
|
|
21
|
+ else if (c >= 'A' && c <= 'M') c += 13;
|
|
22
|
+ else if (c >= 'n' && c <= 'z') c -= 13;
|
|
23
|
+ else if (c >= 'N' && c <= 'Z') c -= 13;
|
|
24
|
+ sb.append(c);
|
|
25
|
+ }
|
|
26
|
+ return sb.toString();
|
17
|
27
|
}
|
18
|
28
|
|
19
|
29
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
30
|
+ return crypt(text);
|
21
|
31
|
}
|
22
|
32
|
|
23
|
33
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
34
|
+ return crypt(text);
|
25
|
35
|
}
|
26
|
36
|
|
27
|
37
|
public static String rotate(String s, Character c) {
|
28
|
|
-
|
29
|
|
- return "";
|
|
38
|
+ StringBuilder rotate = new StringBuilder();
|
|
39
|
+ int indexOfC = s.indexOf(c);
|
|
40
|
+ rotate.append(s.substring(indexOfC,s.length()));
|
|
41
|
+ rotate.append(s.substring(0,indexOfC));
|
|
42
|
+ return rotate.toString();
|
30
|
43
|
}
|
31
|
44
|
|
32
|
45
|
}
|