浏览代码

Merge ba4ca8a2ae116789eca8680a942600068c7fc708 into acdd71eb540bd8356719c3274bc7bbbdbd82ea21

Jessica Campbell 6 年前
父节点
当前提交
48c3c3d1c6
没有帐户链接到提交者的电子邮件
共有 4 个文件被更改,包括 72 次插入9 次删除
  1. 7
    0
      Crypto/src/CaesarCipher.java
  2. 43
    9
      Crypto/src/ROT13.java
  3. 15
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 7
- 0
Crypto/src/CaesarCipher.java 查看文件

1
+public class CaesarCipher extends ROT13{
2
+
3
+    CaesarCipher(Character cs, Character cf) {
4
+       super('a', 'd');
5
+    }
6
+
7
+}

+ 43
- 9
Crypto/src/ROT13.java 查看文件

10
     ROT13() {
10
     ROT13() {
11
     }
11
     }
12
 
12
 
13
+//    public String shift13(String str, Character ch) {
14
+//        StringBuilder shifted = new StringBuilder();
15
+//        Character[] strToArray = new Character[0];
16
+//        for (int i = 0; i < strToArray.length; i++) {
17
+//            if (i >= 97 && i <= 122) {
18
+//                i += 13;
19
+//                shifted.append(i);
20
+//            }
21
+//            if (i <= 90 && i >= 65) {
22
+//                i += 13;
23
+//                shifted.append(i);
24
+//            } else {
25
+//                shifted.append(i);
26
+//            }
27
+//        }
28
+//        return shifted.toString();
29
+//    }
13
 
30
 
14
-    public String crypt(String text) throws UnsupportedOperationException {
15
 
31
 
16
-        return "";
32
+    public String crypt(String text) throws UnsupportedOperationException {
33
+        StringBuilder sb = new StringBuilder();
34
+        for (int i = 0; i < text.length(); i++) {
35
+            char c= text.charAt(i);
36
+            if (c >= 'a' && c <= 'm') {
37
+                c += 13;
38
+            } else if (c >= 'A' && c <= 'M') {
39
+                c += 13;
40
+            } else if (c >= 'n' && c <= 'z') {
41
+                c -= 13;
42
+            } else if (c >= 'N' && c <= 'Z') {
43
+                c -= 13;
44
+            }
45
+            sb.append(c);
46
+        }
47
+        return sb.toString();
17
     }
48
     }
18
 
49
 
19
-    public String encrypt(String text) {
20
-        return text;
50
+    public String encrypt (String text){
51
+        return crypt(text);
21
     }
52
     }
22
 
53
 
23
-    public String decrypt(String text) {
24
-        return text;
54
+    public String decrypt (String text){
55
+        return crypt(text);
25
     }
56
     }
26
 
57
 
27
-    public static String rotate(String s, Character c) {
28
-
29
-        return "";
58
+    public static String rotate (String s, Character c){
59
+        int startIndex = s.indexOf(c);
60
+        StringBuilder sb = new StringBuilder();
61
+        sb.append(s.substring(startIndex, s.length()));
62
+        sb.append(s.substring(0, startIndex));
63
+        return sb.toString();
30
     }
64
     }
31
 
65
 
32
 }
66
 }

+ 15
- 0
SimpleCrypt.iml 查看文件

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
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/src" isTestSource="false" />
8
+      <excludeFolder url="file://$MODULE_DIR$/target" />
9
+    </content>
10
+    <orderEntry type="inheritedJdk" />
11
+    <orderEntry type="sourceFolder" forTests="false" />
12
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
13
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
14
+  </component>
15
+</module>

+ 7
- 0
pom.xml 查看文件

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>SimpleCrypt</artifactId>
8
     <artifactId>SimpleCrypt</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+    </dependencies>
10
 
17
 
11
 
18
 
12
 </project>
19
 </project>