Browse Source

Merge 5c148a667c5f1df299c9d43d62783425c8153741 into acdd71eb540bd8356719c3274bc7bbbdbd82ea21

Peteyocre 6 years ago
parent
commit
0627391125
No account linked to committer's email
4 changed files with 58 additions and 13 deletions
  1. 26
    5
      Crypto/src/ROT13.java
  2. 9
    8
      Crypto/src/ROT13Test.java
  3. 16
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 26
- 5
Crypto/src/ROT13.java View File

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

+ 9
- 8
Crypto/src/ROT13Test.java View File

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

+ 16
- 0
SimpleCrypt.iml View File

@@ -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="true" />
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: org.testng:testng:6.14.2" level="project" />
13
+    <orderEntry type="library" name="Maven: com.beust:jcommander:1.72" level="project" />
14
+    <orderEntry type="library" name="Maven: org.apache-extras.beanshell:bsh:2.0b6" level="project" />
15
+  </component>
16
+</module>

+ 7
- 0
pom.xml View File

@@ -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>org.testng</groupId>
13
+            <artifactId>testng</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+    </dependencies>
10 17
 
11 18
 
12 19
 </project>