|
|
@@ -19,16 +19,37 @@ public class ROT13 {
|
|
19
|
19
|
|
|
20
|
20
|
|
|
21
|
21
|
public String crypt(String text) throws UnsupportedOperationException {
|
|
22
|
|
-
|
|
23
|
|
- return "";
|
|
|
22
|
+ return text;
|
|
24
|
23
|
}
|
|
25
|
24
|
|
|
26
|
25
|
public String encrypt(String text) {
|
|
27
|
|
- return text;
|
|
|
26
|
+ String result = "";
|
|
|
27
|
+ int rotator = cf-cs;
|
|
|
28
|
+ boolean isUppercase = false;
|
|
|
29
|
+ for(int i=0; i<text.length(); i++){
|
|
|
30
|
+ isUppercase = Character.isUpperCase(text.charAt(i));
|
|
|
31
|
+ int temp = Character.toLowerCase(text.charAt(i));
|
|
|
32
|
+ if (temp==32){
|
|
|
33
|
+ } else if(temp+rotator < 122){
|
|
|
34
|
+ temp = (int)text.charAt(i)+rotator;
|
|
|
35
|
+ } else {
|
|
|
36
|
+ temp = 96 + ((temp+rotator)-122);
|
|
|
37
|
+ }
|
|
|
38
|
+ if(isUppercase){Character.toUpperCase(temp);}
|
|
|
39
|
+ result+= (char)temp;
|
|
|
40
|
+ }
|
|
|
41
|
+ return result;
|
|
28
|
42
|
}
|
|
29
|
43
|
|
|
30
|
44
|
public String decrypt(String text) {
|
|
31
|
|
- return text;
|
|
|
45
|
+ String result = "";
|
|
|
46
|
+ int temp = 0;
|
|
|
47
|
+ int rotator = cf-cs;
|
|
|
48
|
+ for(int i=0; i<text.length(); i++){
|
|
|
49
|
+ temp = (int)text.charAt(i)-rotator;
|
|
|
50
|
+ result+= (char)temp;
|
|
|
51
|
+ }
|
|
|
52
|
+ return result;
|
|
32
|
53
|
}
|
|
33
|
54
|
|
|
34
|
55
|
public static String rotate(String s, Character c) {
|