Peter McCormick 6 gadus atpakaļ
vecāks
revīzija
93e8d84fcc
4 mainītis faili ar 59 papildinājumiem un 12 dzēšanām
  1. 27
    4
      Crypto/src/ROT13.java
  2. 9
    8
      Crypto/src/ROT13Test.java
  3. 16
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 27
- 4
Crypto/src/ROT13.java Parādīt failu

12
 
12
 
13
 
13
 
14
     public String crypt(String text) throws UnsupportedOperationException {
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
     public String encrypt(String text) {
32
     public String encrypt(String text) {
20
-        return text;
33
+        return crypt(text);
21
     }
34
     }
22
 
35
 
23
     public String decrypt(String text) {
36
     public String decrypt(String text) {
24
-        return text;
37
+        return crypt(text);
25
     }
38
     }
26
 
39
 
27
     public static String rotate(String s, Character c) {
40
     public static String rotate(String s, Character c) {
28
 
41
 
29
-        return "";
42
+        int startingIndex = 0;
43
+        StringBuilder textSB = new StringBuilder();
44
+        startingIndex = s.indexOf(c);
45
+
46
+        for (int i = startingIndex; i < s.length(); i++) {
47
+            textSB.append(s.charAt(i));
48
+        }
49
+        for (int i = 0; i < startingIndex; i++) {
50
+            textSB.append(s.charAt(i));
51
+        }
52
+        return textSB.toString();
30
     }
53
     }
31
 
54
 
32
 }
55
 }

+ 9
- 8
Crypto/src/ROT13Test.java Parādīt failu

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

+ 16
- 0
SimpleCrypt.iml Parādīt failu

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 Parādīt failu

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>SimpleCrypt</artifactId>
8
     <artifactId>SimpleCrypt</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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
 </project>
19
 </project>