#5 Completed Simple Crypt

オープン
mpierse が 5 個のコミットを mpierse/SimpleCrypt:master から master へマージしようとしています
共有7 個のファイルを変更した75 個の追加7 個の削除を含む
  1. バイナリ
      .DS_Store
  2. バイナリ
      Crypto/.DS_Store
  3. 1
    1
      Crypto/Test/ROT13Test.java
  4. バイナリ
      Crypto/src/.DS_Store
  5. 50
    6
      Crypto/src/ROT13.java
  6. 16
    0
      SimpleCrypt.iml
  7. 8
    0
      pom.xml

バイナリ
.DS_Store ファイルの表示


バイナリ
Crypto/.DS_Store ファイルの表示


Crypto/src/ROT13Test.java → Crypto/Test/ROT13Test.java ファイルの表示

@@ -14,7 +14,6 @@ public class ROT13Test {
14 14
         // When
15 15
         ROT13 cipher = new ROT13();
16 16
         String actual = cipher.rotate(s1, 'A');
17
-
18 17
         // Then
19 18
         assertTrue(actual.equals(s2));
20 19
     }
@@ -28,6 +27,7 @@ public class ROT13Test {
28 27
         // When
29 28
         ROT13 cipher = new ROT13();
30 29
         String actual = cipher.rotate(s1, 'D');
30
+        System.out.println(actual);
31 31
 
32 32
         // Then
33 33
         assertTrue(actual.equals(s2));

バイナリ
Crypto/src/.DS_Store ファイルの表示


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

@@ -4,29 +4,73 @@ import static java.lang.Character.toLowerCase;
4 4
 
5 5
 public class ROT13  {
6 6
 
7
+    Character cs;
8
+    Character cf;
9
+
7 10
     ROT13(Character cs, Character cf) {
11
+        this.cs= cs;
12
+        this.cf=cf;
8 13
     }
9 14
 
10 15
     ROT13() {
16
+        this.cs='a';
17
+        this.cf='m';
11 18
     }
12 19
 
13 20
 
14 21
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
22
+      return encrypt(encrypt(text));
17 23
     }
18 24
 
19 25
     public String encrypt(String text) {
20
-        return text;
26
+        String result = "";
27
+        int rotator = cf-cs;
28
+        boolean isUppercase = false;
29
+        for(int i=0; i<text.length(); i++){
30
+            isUppercase = Character.isUpperCase(text.charAt(i));
31
+            int temp = Character.toLowerCase(text.charAt(i));
32
+            if (temp<97|temp>122){
33
+            } else if(temp+rotator < 122){
34
+            temp = (int)text.charAt(i)+rotator;
35
+            } else {
36
+                temp = 96 + ((temp+rotator)-122);
37
+            }
38
+            if(isUppercase){temp=Character.toUpperCase(temp);}
39
+            result+= (char)temp;
40
+        }
41
+        return result;
21 42
     }
22 43
 
23 44
     public String decrypt(String text) {
24
-        return text;
45
+
46
+        String result = "";
47
+        int rotator = cf-cs;
48
+        boolean isUppercase = false;
49
+        for(int i=0; i<text.length(); i++){
50
+            isUppercase = Character.isUpperCase(text.charAt(i));
51
+            int temp = Character.toLowerCase(text.charAt(i));
52
+            if (temp<97|temp>122){
53
+            } else if(temp-rotator > 97){
54
+                temp = (int)text.charAt(i)-rotator;
55
+            } else {
56
+                temp = 122 - (96-(temp-rotator));
57
+            }
58
+            if(isUppercase){temp=Character.toUpperCase(temp);}
59
+            result+= (char)temp;
60
+        }
61
+        return result;
25 62
     }
26 63
 
27 64
     public static String rotate(String s, Character c) {
28
-
29
-        return "";
65
+        String result = "";
66
+        String reference = s+s;
67
+        int rotator = Character.toLowerCase(c)-'a';
68
+        boolean isUppercase = false;
69
+        for(int i=0; i<s.length(); i++){
70
+          Character temp = reference.charAt(i+rotator);
71
+            result+= temp;
72
+        }
73
+        return result;
30 74
     }
31 75
 
32 76
 }

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

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

@@ -7,6 +7,14 @@
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>4.12</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>