|
@@ -4,6 +4,9 @@ import static java.lang.Character.toLowerCase;
|
4
|
4
|
|
5
|
5
|
public class ROT13 {
|
6
|
6
|
|
|
7
|
+ private final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
8
|
+ private final string lowercaseStart = "abcdefghijklmnopqrstuvwxyz";
|
|
9
|
+
|
7
|
10
|
ROT13(Character cs, Character cf) {
|
8
|
11
|
}
|
9
|
12
|
|
|
@@ -12,21 +15,42 @@ public class ROT13 {
|
12
|
15
|
|
13
|
16
|
|
14
|
17
|
public String crypt(String text) throws UnsupportedOperationException {
|
15
|
|
-
|
16
|
|
- return "";
|
|
18
|
+ StringBuilder sb = new StringBuilder();
|
|
19
|
+ for (int i = 0; i < input.length(); i++) {
|
|
20
|
+ char c = text.charAt(i);
|
|
21
|
+ if (c >= 'a' && c <= 'm') c += 13;
|
|
22
|
+ else if (c >= 'A' && c <= 'M') c += 13;
|
|
23
|
+ else if (c >= 'n' && c <= 'z') c -= 13;
|
|
24
|
+ else if (c >= 'N' && c <= 'Z') c -= 13;
|
|
25
|
+ sb.append(c);
|
|
26
|
+ }
|
|
27
|
+ return sb.toString();
|
|
28
|
+ }
|
17
|
29
|
}
|
18
|
30
|
|
19
|
31
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
32
|
+ crypt(text);
|
21
|
33
|
}
|
22
|
34
|
|
23
|
35
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
36
|
+ crypt(text);
|
25
|
37
|
}
|
26
|
38
|
|
27
|
39
|
public static String rotate(String s, Character c) {
|
|
40
|
+ if ( Character.isLowerCase( (s) c ) )
|
|
41
|
+ {
|
|
42
|
+ return ( ( c - (int)'a' + 13 ) % 26 + (int)'a' );
|
|
43
|
+ }
|
|
44
|
+ else
|
|
45
|
+ if ( Character.isUpperCase( (s) c ) )
|
|
46
|
+ {
|
|
47
|
+ return ( ( c - (int)'A' + 13 ) % 26 + (int)'A' );
|
|
48
|
+ }
|
|
49
|
+ else
|
|
50
|
+ {
|
|
51
|
+ return (int)' ';
|
|
52
|
+ }
|
28
|
53
|
|
29
|
|
- return "";
|
30
|
54
|
}
|
31
|
55
|
|
32
|
56
|
}
|