|
@@ -1,32 +1,81 @@
|
|
1
|
+import java.util.Arrays;
|
|
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
|
|
|
7
|
+
|
5
|
8
|
public class ROT13 {
|
6
|
9
|
|
7
|
10
|
ROT13(Character cs, Character cf) {
|
8
|
11
|
}
|
9
|
12
|
|
10
|
13
|
ROT13() {
|
|
14
|
+
|
11
|
15
|
}
|
12
|
16
|
|
13
|
17
|
|
14
|
18
|
public String crypt(String text) throws UnsupportedOperationException {
|
15
|
19
|
|
16
|
|
- return "";
|
|
20
|
+ return encrypt(text);
|
17
|
21
|
}
|
18
|
22
|
|
19
|
23
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
24
|
+
|
|
25
|
+ //a - z is 97 - 122
|
|
26
|
+ //A - Z is 65 - 90
|
|
27
|
+ // get char value of c and store it as crypto
|
|
28
|
+ char c = 'n';
|
|
29
|
+ char cBig = 'N';
|
|
30
|
+ int cryptoLowerCase = (c - 97) % 26 ;
|
|
31
|
+ int cryptoUpperCase = (cBig - 65) % 26 ;
|
|
32
|
+
|
|
33
|
+ char[] arr = text.toCharArray();
|
|
34
|
+
|
|
35
|
+ for (int i = 0; i < arr.length; i++){
|
|
36
|
+ if (isLowerCase(arr[i])){
|
|
37
|
+ arr[i] = (char) ((int) arr[i] + cryptoLowerCase);
|
|
38
|
+ if (arr[i] > 'z'){
|
|
39
|
+ arr[i] = (char) ((int) arr[i] - 26);
|
|
40
|
+ }
|
|
41
|
+ } else if (isUpperCase(arr[i])){
|
|
42
|
+ arr[i] = (char) ((int) arr[i] + cryptoUpperCase);
|
|
43
|
+ if (arr[i] > 'Z'){
|
|
44
|
+ arr[i] = (char) ((int) arr[i] - 26);
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+ }
|
|
48
|
+ String result = String.valueOf(arr);
|
|
49
|
+ return result;
|
21
|
50
|
}
|
22
|
51
|
|
23
|
52
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
53
|
+
|
|
54
|
+ return encrypt(text);
|
25
|
55
|
}
|
26
|
56
|
|
|
57
|
+
|
27
|
58
|
public static String rotate(String s, Character c) {
|
28
|
59
|
|
29
|
|
- return "";
|
|
60
|
+// char[] arr = s.toCharArray();
|
|
61
|
+// int indexOfC = Arrays.asList(arr).indexOf(c);
|
|
62
|
+//
|
|
63
|
+// while(indexOfC > 0) {
|
|
64
|
+// for (int i = 1; i < s.length(); i++) {
|
|
65
|
+// char temp = arr[i];
|
|
66
|
+// arr[i] = arr[i + 1];
|
|
67
|
+// arr[i+1] = temp;
|
|
68
|
+// }
|
|
69
|
+// indexOfC--;
|
|
70
|
+// }
|
|
71
|
+// String result = String.valueOf(arr);
|
|
72
|
+// return result;
|
|
73
|
+
|
|
74
|
+ StringBuilder sb = new StringBuilder();
|
|
75
|
+ sb.append(s.substring(s.indexOf(c)));
|
|
76
|
+ sb.append(s.substring(0, s.indexOf(c)));
|
|
77
|
+ return sb.toString();
|
30
|
78
|
}
|
31
|
79
|
|
32
|
|
-}
|
|
80
|
+
|
|
81
|
+}
|