|
@@ -1,8 +1,10 @@
|
|
1
|
+import java.util.Scanner;
|
|
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 {
|
6
|
8
|
|
7
|
9
|
ROT13(Character cs, Character cf) {
|
8
|
10
|
}
|
|
@@ -12,21 +14,37 @@ public class ROT13 {
|
12
|
14
|
|
13
|
15
|
|
14
|
16
|
public String crypt(String text) throws UnsupportedOperationException {
|
|
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')) {
|
|
21
|
+ c += 13;
|
|
22
|
+ } else if ((c >= 'a') && (c <= 'm')) {
|
|
23
|
+ c += 13;
|
|
24
|
+ } else if ((c >= 'N') && (c <= 'Z')) {
|
|
25
|
+ c -= 13;
|
|
26
|
+ } else if ((c >= 'n') && (c <= 'z')) {
|
|
27
|
+ c -= 13;
|
|
28
|
+ }
|
|
29
|
+ sb.append(c);
|
|
30
|
+ }
|
|
31
|
+ return sb.toString();
|
15
|
32
|
|
16
|
|
- return "";
|
17
|
|
- }
|
18
|
|
-
|
19
|
|
- public String encrypt(String text) {
|
20
|
|
- return text;
|
21
|
33
|
}
|
22
|
34
|
|
23
|
|
- public String decrypt(String text) {
|
24
|
|
- return text;
|
|
35
|
+ public String encrypt (String text){
|
|
36
|
+ return crypt(text);
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public String decrypt (String text){
|
|
40
|
+ return crypt(text);
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ public static String rotate (String s, Character c){
|
|
44
|
+ int firstIndex = s.indexOf(c);
|
|
45
|
+ StringBuilder sb = new StringBuilder();
|
|
46
|
+ sb.append(s.substring(firstIndex, s.length()));
|
|
47
|
+ sb.append(s.substring(0, firstIndex));
|
|
48
|
+ return sb.toString();
|
|
49
|
+ }
|
25
|
50
|
}
|
26
|
|
-
|
27
|
|
- public static String rotate(String s, Character c) {
|
28
|
|
-
|
29
|
|
- return "";
|
30
|
|
- }
|
31
|
|
-
|
32
|
|
-}
|