Katrice Williams-Dredden 6 年前
父节点
当前提交
76cfe01429
共有 3 个文件被更改,包括 62 次插入4 次删除
  1. 2
    0
      Crypto/Test/ROT13Test.java
  2. 48
    4
      Crypto/src/ROT13.java
  3. 12
    0
      SimpleCrypt.iml

Crypto/src/ROT13Test.java → Crypto/Test/ROT13Test.java 查看文件

@@ -1,6 +1,8 @@
1 1
 import org.junit.Test;
2 2
 
3 3
 import static org.junit.Assert.*;
4
+import org.testng.annotations.Test;
5
+
4 6
 
5 7
 public class ROT13Test {
6 8
 

+ 48
- 4
Crypto/src/ROT13.java 查看文件

@@ -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
 }

+ 12
- 0
SimpleCrypt.iml 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <excludeFolder url="file://$MODULE_DIR$/target" />
8
+    </content>
9
+    <orderEntry type="inheritedJdk" />
10
+    <orderEntry type="sourceFolder" forTests="false" />
11
+  </component>
12
+</module>