|
@@ -1,32 +1,53 @@
|
1
|
1
|
import static java.lang.Character.isLowerCase;
|
2
|
2
|
import static java.lang.Character.isUpperCase;
|
3
|
|
-import static java.lang.Character.toLowerCase;
|
|
3
|
+//import static java.lang.Character.toLowerCase;
|
4
|
4
|
|
5
|
5
|
public class ROT13 {
|
|
6
|
+ private int shift;
|
6
|
7
|
|
7
|
8
|
ROT13(Character cs, Character cf) {
|
|
9
|
+ this.shift = cf - cs;
|
8
|
10
|
}
|
9
|
11
|
|
10
|
12
|
ROT13() {
|
|
13
|
+ this.shift = 13;
|
11
|
14
|
}
|
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<text.length(); i++){
|
|
20
|
+ if(isLowerCase(text.charAt(i))){
|
|
21
|
+ sb.append((char)(((int)(text.charAt(i))+ shift - 97)%26+97));
|
|
22
|
+ }
|
|
23
|
+ else if(isUpperCase(text.charAt(i))){
|
|
24
|
+ sb.append((char)(((int)(text.charAt(i))+ shift - 65)%26+65));
|
|
25
|
+ }
|
|
26
|
+ else {
|
|
27
|
+ sb.append(text.charAt(i));
|
|
28
|
+ }
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ return sb.toString();
|
17
|
32
|
}
|
18
|
33
|
|
19
|
34
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
35
|
+
|
|
36
|
+ return crypt(text);
|
21
|
37
|
}
|
22
|
38
|
|
23
|
39
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+ return crypt(text);
|
25
|
43
|
}
|
26
|
44
|
|
27
|
45
|
public static String rotate(String s, Character c) {
|
|
46
|
+ String subStr = s.substring(0, s.indexOf(c));
|
|
47
|
+ String subStr1 = s.substring(s.indexOf(c));
|
|
48
|
+
|
28
|
49
|
|
29
|
|
- return "";
|
|
50
|
+ return subStr1.concat(subStr);
|
30
|
51
|
}
|
31
|
52
|
|
32
|
53
|
}
|