Garrett Arant 6 年 前
コミット
a95ed6a5e2
共有6 個のファイルを変更した73 個の追加7 個の削除を含む
  1. 7
    0
      Crypto/src/CaesarCipher.java
  2. 19
    6
      Crypto/src/ROT13.java
  3. 2
    1
      Crypto/src/ROT13Test.java
  4. 16
    0
      SimpleCrypt.iml
  5. 7
    0
      pom.xml
  6. 22
    0
      target/classes/Crypto.iml

+ 7
- 0
Crypto/src/CaesarCipher.java ファイルの表示

@@ -0,0 +1,7 @@
1
+package src;
2
+
3
+public class CaesarCipher extends ROT13 {
4
+    CaesarCipher(Character cs, Character cf) {
5
+        super(cs, cf);
6
+    }
7
+}

+ 19
- 6
Crypto/src/ROT13.java ファイルの表示

@@ -1,3 +1,5 @@
1
+package src;
2
+
1 3
 import static java.lang.Character.isLowerCase;
2 4
 import static java.lang.Character.isUpperCase;
3 5
 import static java.lang.Character.toLowerCase;
@@ -12,21 +14,32 @@ public class ROT13  {
12 14
 
13 15
 
14 16
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
17
+        StringBuilder sb = new StringBuilder();
18
+        for (int i = 0; i < text.length(); i++) {
19
+            char c = text.charAt(i);
20
+            if (c >= 'a' && c <= 'm') c += 13;
21
+            else if (c >= 'A' && c <= 'M') c += 13;
22
+            else if (c >= 'n' && c <= 'z') c -= 13;
23
+            else if (c >= 'N' && c <= 'Z') c -= 13;
24
+            sb.append(c);
25
+        }
26
+        return sb.toString();
17 27
     }
18 28
 
19 29
     public String encrypt(String text) {
20
-        return text;
30
+        return crypt(text);
21 31
     }
22 32
 
23 33
     public String decrypt(String text) {
24
-        return text;
34
+        return crypt(text);
25 35
     }
26 36
 
27 37
     public static String rotate(String s, Character c) {
28
-
29
-        return "";
38
+        StringBuilder rotate = new StringBuilder();
39
+        int indexOfC = s.indexOf(c);
40
+        rotate.append(s.substring(indexOfC,s.length()));
41
+        rotate.append(s.substring(0,indexOfC));
42
+        return rotate.toString();
30 43
     }
31 44
 
32 45
 }

+ 2
- 1
Crypto/src/ROT13Test.java ファイルの表示

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

+ 16
- 0
SimpleCrypt.iml ファイルの表示

@@ -0,0 +1,16 @@
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" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/Tests" 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" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 7
- 0
pom.xml ファイルの表示

@@ -7,6 +7,13 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 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 19
 </project>

+ 22
- 0
target/classes/Crypto.iml ファイルの表示

@@ -0,0 +1,22 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$">
6
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+    </content>
8
+    <orderEntry type="inheritedJdk" />
9
+    <orderEntry type="sourceFolder" forTests="false" />
10
+    <orderEntry type="library" name="Arquillian JUnit:Release" level="project" />
11
+    <orderEntry type="module-library">
12
+      <library name="JUnit4">
13
+        <CLASSES>
14
+          <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
15
+          <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
16
+        </CLASSES>
17
+        <JAVADOC />
18
+        <SOURCES />
19
+      </library>
20
+    </orderEntry>
21
+  </component>
22
+</module>