#7 tkhong102

Отворено
tkhong102 жели да споји 1 комит(е) из tkhong102/SimpleCrypt:master у master
4 измењених фајлова са 58 додато и 14 уклоњено
  1. 28
    6
      Crypto/src/ROT13.java
  2. 8
    8
      Crypto/src/ROT13Test.java
  3. 15
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 28
- 6
Crypto/src/ROT13.java Прегледај датотеку

@@ -10,23 +10,45 @@ public class ROT13  {
10 10
     ROT13() {
11 11
     }
12 12
 
13
-
14 13
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
14
+        StringBuilder builder = new StringBuilder();
15
+        for (int i = 0; i < text.length(); i++) {
16
+            char c = text.charAt(i);
17
+            if(c>='a' && c<= 'm') c+= 13;
18
+            else if(c >= 'A' && c <='M') c+=13;
19
+            else if (c >= 'n' && c<= 'z') c-= 13;
20
+            else if(c >= 'N' && c <= 'Z') c -= 13;
21
+            builder.append(c);
22
+        }
23
+        return builder.toString();
17 24
     }
18 25
 
19 26
     public String encrypt(String text) {
20
-        return text;
27
+
28
+        return crypt(text);
21 29
     }
22 30
 
23 31
     public String decrypt(String text) {
24
-        return text;
32
+
33
+        return crypt(text);
25 34
     }
26 35
 
27 36
     public static String rotate(String s, Character c) {
28 37
 
29
-        return "";
38
+        int index = 0;
39
+        for (int i = 0; i < s.length(); i++) {
40
+            if(s.charAt(i)==(c)){
41
+                index = i;
42
+            }
43
+        }
44
+        StringBuilder builder = new StringBuilder();
45
+        for (int i = index; i < s.length(); i++) {
46
+            builder.append(s.charAt(i));
47
+        }
48
+        for (int i = 0; i < index ; i++) {
49
+            builder.append(s.charAt(i));
50
+        }
51
+        return builder.toString();
30 52
     }
31 53
 
32 54
 }

+ 8
- 8
Crypto/src/ROT13Test.java Прегледај датотеку

@@ -1,6 +1,6 @@
1
-import org.junit.Test;
2 1
 
3
-import static org.junit.Assert.*;
2
+import org.junit.Assert;
3
+import org.junit.Test;
4 4
 
5 5
 public class ROT13Test {
6 6
 
@@ -16,7 +16,7 @@ public class ROT13Test {
16 16
         String actual = cipher.rotate(s1, 'A');
17 17
 
18 18
         // Then
19
-        assertTrue(actual.equals(s2));
19
+        Assert.assertTrue(actual.equals(s2));
20 20
     }
21 21
 
22 22
     @Test
@@ -30,7 +30,7 @@ public class ROT13Test {
30 30
         String actual = cipher.rotate(s1, 'D');
31 31
 
32 32
         // Then
33
-        assertTrue(actual.equals(s2));
33
+        Assert.assertTrue(actual.equals(s2));
34 34
     }
35 35
 
36 36
     @Test
@@ -45,7 +45,7 @@ public class ROT13Test {
45 45
         System.out.println(s1);
46 46
         System.out.println(actual);
47 47
         // Then
48
-        assertTrue(actual.equals(s2));
48
+        Assert.assertTrue(actual.equals(s2));
49 49
     }
50 50
 
51 51
     @Test
@@ -64,14 +64,14 @@ public class ROT13Test {
64 64
         System.out.println(Q1);
65 65
         System.out.println(A1);
66 66
         // Then
67
-        assertTrue(actual.equals(A1));
67
+        Assert.assertTrue(actual.equals(A1));
68 68
 
69 69
         // When
70 70
         String actual2 = cipher.decrypt(Q2);
71 71
         System.out.println(Q2);
72 72
         System.out.println(A2);
73 73
         // Then
74
-        assertTrue(actual2.equals(A2));
74
+        Assert.assertTrue(actual2.equals(A2));
75 75
     }
76 76
     @Test
77 77
     public void cryptTest2() {
@@ -85,7 +85,7 @@ public class ROT13Test {
85 85
         String actual = cipher.crypt(cipher.crypt(Q1));
86 86
         System.out.println(actual);
87 87
         // Then
88
-        assertTrue(actual.equals(Q1));
88
+        Assert.assertTrue(actual.equals(Q1));
89 89
     }
90 90
 
91 91
 }

+ 15
- 0
SimpleCrypt.iml Прегледај датотеку

@@ -0,0 +1,15 @@
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 Прегледај датотеку

@@ -8,5 +8,12 @@
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
+    </dependencies>
11 18
 
12 19
 </project>