|
@@ -1,8 +1,14 @@
|
1
|
1
|
import static java.lang.Character.isLowerCase;
|
2
|
2
|
import static java.lang.Character.isUpperCase;
|
3
|
3
|
import static java.lang.Character.toLowerCase;
|
|
4
|
+import java.lang.StringBuilder;
|
|
5
|
+import java.lang.String;
|
|
6
|
+import java.lang.StringBuffer;
|
4
|
7
|
|
5
|
8
|
public class ROT13 {
|
|
9
|
+ static int length = 0;
|
|
10
|
+ static int start = 0;
|
|
11
|
+ String cryptText = "";
|
6
|
12
|
|
7
|
13
|
ROT13(Character cs, Character cf) {
|
8
|
14
|
}
|
|
@@ -12,21 +18,51 @@ public class ROT13 {
|
12
|
18
|
|
13
|
19
|
|
14
|
20
|
public String crypt(String text) throws UnsupportedOperationException {
|
|
21
|
+ StringBuilder builder = new StringBuilder();
|
15
|
22
|
|
16
|
|
- return "";
|
|
23
|
+ for(int i = 0; i<text.length(); i++){
|
|
24
|
+ char c = text.charAt(i);
|
|
25
|
+ if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
|
|
26
|
+ else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
|
|
27
|
+ builder.append(c);
|
|
28
|
+ }
|
|
29
|
+ text = builder.toString();
|
|
30
|
+
|
|
31
|
+ return text;
|
17
|
32
|
}
|
18
|
33
|
|
19
|
34
|
public String encrypt(String text) {
|
|
35
|
+ for(int i = 0; i<text.length(); i++){
|
|
36
|
+ char ch = text.charAt(i);
|
|
37
|
+ if(ch>= 'A' && ch<='Z'){
|
|
38
|
+ ch = (char)(ch+13);
|
|
39
|
+ if (ch > 'Z') {
|
|
40
|
+ ch = (char)(ch-26);
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+ else if(ch>= 'a' && ch<='z'){
|
|
44
|
+ ch = (char)(ch+13);
|
|
45
|
+ if(ch>'z'){
|
|
46
|
+ ch = (char)(ch-26);
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+ cryptText = cryptText+ch;
|
|
50
|
+ }
|
|
51
|
+ text = cryptText;
|
20
|
52
|
return text;
|
21
|
53
|
}
|
22
|
54
|
|
23
|
55
|
public String decrypt(String text) {
|
|
56
|
+ encrypt(text);
|
24
|
57
|
return text;
|
25
|
58
|
}
|
26
|
59
|
|
27
|
60
|
public static String rotate(String s, Character c) {
|
|
61
|
+ length = s.length();
|
|
62
|
+ start = s.indexOf(c);
|
|
63
|
+ int rotate = length - start;
|
|
64
|
+ return s.substring(start, length) + s.substring(0, start);
|
28
|
65
|
|
29
|
|
- return "";
|
30
|
66
|
}
|
31
|
67
|
|
32
|
68
|
}
|