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