瀏覽代碼

finished commit

Joshua Chung 6 年之前
父節點
當前提交
99a2c96277
共有 5 個文件被更改,包括 93 次插入34 次删除
  1. 58
    0
      Crypto/src/Main/java/ROT13.java
  2. 1
    2
      Crypto/src/Main/javaT/ROT13Test.java
  3. 0
    32
      Crypto/src/ROT13.java
  4. 20
    0
      SimpleCrypt.iml
  5. 14
    0
      pom.xml

+ 58
- 0
Crypto/src/Main/java/ROT13.java 查看文件

@@ -0,0 +1,58 @@
1
+import static java.lang.Character.isLowerCase;
2
+import static java.lang.Character.isUpperCase;
3
+import static java.lang.Character.toLowerCase;
4
+
5
+public class ROT13  {
6
+
7
+    ROT13(Character cs, Character cf) {
8
+    }
9
+
10
+    ROT13() {
11
+    }
12
+
13
+
14
+    public String crypt(String text) throws UnsupportedOperationException {
15
+
16
+        return encrypt(text);
17
+    }
18
+
19
+    //Turn string into char array, and iterate through it.
20
+    //Separate lower and uppercase letter.
21
+    //if letter is above M, subtract 13 letters, otherwise add 13 letters.
22
+    //return as new string.
23
+    public String encrypt(String text) {
24
+        char[] texts = text.toCharArray();
25
+        for(int i = 0; i < texts.length; i++) {
26
+            char letter = texts[i];
27
+            if(letter >= 'a' && letter <= 'z') {
28
+                if(letter > 'm') {
29
+                    letter -= 13;
30
+                } else {
31
+                    letter += 13;
32
+                }
33
+            } else if (letter >= 'A' && letter <= 'Z') {
34
+                if (letter > 'M') {
35
+                    letter -= 13;
36
+                } else {
37
+                    letter += 13;
38
+                }
39
+            }
40
+            texts[i] = letter;
41
+        }
42
+
43
+        return new String(texts);
44
+    }
45
+
46
+    public String decrypt(String text) {
47
+        return encrypt(text);
48
+    }
49
+
50
+    //set s as c and return as new substring and append it.
51
+    //then append a subsequence of the specified charsequence to this sequence.
52
+    //convert to string then return.
53
+    public static String rotate(String s, Character c) {
54
+        StringBuilder string = new StringBuilder();
55
+        return string.append(s.substring(s.indexOf(c))).append(s, 0, s.indexOf(c)).toString();
56
+    }
57
+
58
+}

Crypto/src/ROT13Test.java → Crypto/src/Main/javaT/ROT13Test.java 查看文件

@@ -1,6 +1,5 @@
1 1
 import org.junit.Test;
2
-
3
-import static org.junit.Assert.*;
2
+import static org.junit.jupiter.api.Assertions.assertTrue;
4 3
 
5 4
 public class ROT13Test {
6 5
 

+ 0
- 32
Crypto/src/ROT13.java 查看文件

@@ -1,32 +0,0 @@
1
-import static java.lang.Character.isLowerCase;
2
-import static java.lang.Character.isUpperCase;
3
-import static java.lang.Character.toLowerCase;
4
-
5
-public class ROT13  {
6
-
7
-    ROT13(Character cs, Character cf) {
8
-    }
9
-
10
-    ROT13() {
11
-    }
12
-
13
-
14
-    public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
17
-    }
18
-
19
-    public String encrypt(String text) {
20
-        return text;
21
-    }
22
-
23
-    public String decrypt(String text) {
24
-        return text;
25
-    }
26
-
27
-    public static String rotate(String s, Character c) {
28
-
29
-        return "";
30
-    }
31
-
32
-}

+ 20
- 0
SimpleCrypt.iml 查看文件

@@ -0,0 +1,20 @@
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/Main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/src/Main/javaT" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.0-M1" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
15
+    <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.3.0-M1" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
19
+  </component>
20
+</module>

+ 14
- 0
pom.xml 查看文件

@@ -7,6 +7,20 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>junit</groupId>
19
+            <artifactId>junit</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
 
11 25
 
12 26
 </project>