ahsonali vor 6 Jahren
Ursprung
Commit
7cdc490b01
5 geänderte Dateien mit 94 neuen und 33 gelöschten Zeilen
  1. 0
    32
      Crypto/src/ROT13.java
  2. 67
    0
      Crypto/src/main/ROT13.java
  3. 2
    1
      Crypto/src/test/ROT13Test.java
  4. 17
    0
      SimpleCrypt.iml
  5. 8
    0
      pom.xml

+ 0
- 32
Crypto/src/ROT13.java Datei anzeigen

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

+ 67
- 0
Crypto/src/main/ROT13.java Datei anzeigen

@@ -0,0 +1,67 @@
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
+
17
+        StringBuilder sb = new StringBuilder();
18
+
19
+        for(int i = 0; i < text.length(); i++)
20
+        {
21
+            char c = text.charAt(i);
22
+
23
+            if (c >= 'a' && c <= 'm')
24
+            {
25
+                c += 13;
26
+            }
27
+            else if (c >= 'A' && c <= 'M')
28
+            {
29
+                c += 13;
30
+            }
31
+            else if (c >= 'n' && c <= 'z')
32
+            {
33
+                c -= 13;
34
+            }
35
+            else if (c >= 'N' && c <= 'Z')
36
+            {
37
+                c -= 13;
38
+            }
39
+
40
+            sb.append(c);
41
+
42
+        }
43
+
44
+        return sb.toString();
45
+    }
46
+
47
+    public String encrypt(String text)
48
+    {
49
+
50
+        return crypt(text);
51
+    }
52
+
53
+    public String decrypt(String text)
54
+    {
55
+        return crypt(text);
56
+    }
57
+
58
+    public static String rotate(String s, Character c)
59
+    {
60
+        int startIndex = s.indexOf(c);
61
+        StringBuilder sb = new StringBuilder();
62
+        sb.append(s.substring(startIndex, s.length()));
63
+        sb.append(s.substring(0, startIndex));
64
+        return sb.toString();
65
+    }
66
+
67
+}

Crypto/src/ROT13Test.java → Crypto/src/test/ROT13Test.java Datei anzeigen

@@ -6,7 +6,8 @@ public class ROT13Test {
6 6
 
7 7
 
8 8
     @Test
9
-    public void rotateStringTest0() {
9
+    public void rotateStringTest0()
10
+    {
10 11
         // Given
11 12
         String s1 = "ABCDEF";
12 13
         String s2 = "ABCDEF";

+ 17
- 0
SimpleCrypt.iml Datei anzeigen

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

+ 8
- 0
pom.xml Datei anzeigen

@@ -8,5 +8,13 @@
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+        </dependency>
17
+
18
+    </dependencies>
11 19
 
12 20
 </project>