|
@@ -13,20 +13,64 @@ public class ROT13 {
|
13
|
13
|
|
14
|
14
|
public String crypt(String text) throws UnsupportedOperationException {
|
15
|
15
|
|
16
|
|
- return "";
|
|
16
|
+ StringBuilder sb = new StringBuilder();
|
|
17
|
+
|
|
18
|
+ for(int i = 0; i < text.length(); i++){
|
|
19
|
+ char c = text.charAt(i);
|
|
20
|
+
|
|
21
|
+ if (c >= 'a' && c <= 'm'){
|
|
22
|
+ c += 13;
|
|
23
|
+ } else if (c >= 'A' && c <= 'M'){
|
|
24
|
+ c += 13;
|
|
25
|
+ } else if (c >= 'n' && c <= 'z'){
|
|
26
|
+ c -= 13;
|
|
27
|
+ } else if (c >= 'N' && c <= 'Z') {
|
|
28
|
+ c -= 13;
|
|
29
|
+ }
|
|
30
|
+ sb.append(c);
|
|
31
|
+
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ return sb.toString();
|
|
35
|
+ }
|
17
|
36
|
}
|
18
|
37
|
|
19
|
38
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
39
|
+
|
|
40
|
+ return crypt(text);
|
21
|
41
|
}
|
22
|
42
|
|
23
|
43
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
44
|
+
|
|
45
|
+ return crypt(text);
|
25
|
46
|
}
|
26
|
47
|
|
27
|
48
|
public static String rotate(String s, Character c) {
|
28
|
49
|
|
29
|
|
- return "";
|
|
50
|
+ int startIndex = s.indexOf(c);
|
|
51
|
+ StringBuilder sb = new StringBuilder();
|
|
52
|
+ sb.append(s.substring(startIndex, s.length()));
|
|
53
|
+ sb.append(s.substring(0, startIndex));
|
|
54
|
+ return sb.toString();
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+// String sonnet18 = "Shall I compare thee to a summer’s day?\n" +
|
|
58
|
+// "Thou art more lovely and more temperate:\n" +
|
|
59
|
+// "Rough winds do shake the darling buds of May,\n" +
|
|
60
|
+// "And summer’s lease hath all too short a date;\n" +
|
|
61
|
+// "Sometime too hot the eye of heaven shines,\n" +
|
|
62
|
+// "And often is his gold complexion dimm'd;\n" +
|
|
63
|
+// "And every fair from fair sometime declines,\n" +
|
|
64
|
+// "By chance or nature’s changing course untrimm'd;\n" +
|
|
65
|
+// "But thy eternal summer shall not fade,\n" +
|
|
66
|
+// "Nor lose possession of that fair thou ow’st;\n" +
|
|
67
|
+// "Nor shall death brag thou wander’st in his shade,\n" +
|
|
68
|
+// "When in eternal lines to time thou grow’st:\n" +
|
|
69
|
+// " So long as men can breathe or eyes can see,\n" +
|
|
70
|
+// " So long lives this, and this gives life to thee.\n";
|
|
71
|
+//
|
|
72
|
+// public String cryptSonnet (String sonnet ) {
|
|
73
|
+// return crypt(sonnet18);
|
30
|
74
|
}
|
31
|
75
|
|
32
|
76
|
}
|