Browse Source

submission

Rachelle 6 years ago
parent
commit
43257ee866
4 changed files with 67 additions and 10 deletions
  1. 15
    4
      Crypto/Crypto.iml
  2. 38
    4
      Crypto/src/ROT13.java
  3. 2
    2
      Crypto/src/ROT13Test.java
  4. 12
    0
      SimpleCrypt.iml

+ 15
- 4
Crypto/Crypto.iml View File

@@ -7,12 +7,23 @@
7 7
     </content>
8 8
     <orderEntry type="inheritedJdk" />
9 9
     <orderEntry type="sourceFolder" forTests="false" />
10
-    <orderEntry type="library" name="Arquillian JUnit:Release" level="project" />
11 10
     <orderEntry type="module-library">
12
-      <library name="JUnit4">
11
+      <library name="JUnit5.0">
13 12
         <CLASSES>
14
-          <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
15
-          <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
13
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.0.0/junit-jupiter-api-5.0.0.jar!/" />
14
+          <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
15
+          <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.0.0/opentest4j-1.0.0.jar!/" />
16
+          <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.0.0/junit-platform-commons-1.0.0.jar!/" />
17
+        </CLASSES>
18
+        <JAVADOC />
19
+        <SOURCES />
20
+      </library>
21
+    </orderEntry>
22
+    <orderEntry type="module-library">
23
+      <library name="testng">
24
+        <CLASSES>
25
+          <root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/testng.jar!/" />
26
+          <root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/jcommander.jar!/" />
16 27
         </CLASSES>
17 28
         <JAVADOC />
18 29
         <SOURCES />

+ 38
- 4
Crypto/src/ROT13.java View File

@@ -13,20 +13,54 @@ public class ROT13  {
13 13
 
14 14
     public String crypt(String text) throws UnsupportedOperationException {
15 15
 
16
-        return "";
16
+        return encrypt(text);
17 17
     }
18 18
 
19 19
     public String encrypt(String text) {
20
-        return text;
20
+        StringBuilder stringBuilder = new StringBuilder();
21
+
22
+        for (int i = 0; i < text.length(); i++) {
23
+            if(!Character.isLetter(text.charAt(i))){
24
+                stringBuilder.append(text.charAt(i));
25
+            } else if (Character.isLowerCase(text.charAt(i))) {
26
+                stringBuilder.append(rotateLowerCase(text.charAt(i)));
27
+            } else { stringBuilder.append(rotateUpperCase(text.charAt(i)));}
28
+        }
29
+        System.out.println(stringBuilder.toString());
30
+        return stringBuilder.toString();
21 31
     }
22 32
 
23 33
     public String decrypt(String text) {
24
-        return text;
34
+        return encrypt(text);
25 35
     }
26 36
 
27 37
     public static String rotate(String s, Character c) {
38
+        int indexToStart = 0;
39
+        for(int i = 0; i < s.length(); i++){
40
+            if(s.charAt(i) == c){
41
+                indexToStart = i;
42
+            }
43
+        }
44
+        return createNewString(s, indexToStart);
45
+    }
28 46
 
29
-        return "";
47
+    private static String createNewString(String s, int indexToStart) {
48
+        StringBuilder stringBuilder = new StringBuilder(s.substring(indexToStart));
49
+        stringBuilder.append(s.substring(0, indexToStart));
50
+        return stringBuilder.toString();
30 51
     }
31 52
 
53
+    public static char rotateUpperCase(char c){
54
+            if (c + 13 <= 90){
55
+                return (char) (c + 13);
56
+            }
57
+        return (char) (c - 13);
58
+    }
59
+
60
+    public static char rotateLowerCase(char c){
61
+        if (c + 13 <= 122){
62
+            return (char) (c + 13);
63
+        }
64
+        return (char) (c - 13);
65
+    }
32 66
 }

+ 2
- 2
Crypto/src/ROT13Test.java View File

@@ -1,6 +1,6 @@
1
-import org.junit.Test;
1
+import org.testng.annotations.Test;
2 2
 
3
-import static org.junit.Assert.*;
3
+import static org.junit.jupiter.api.Assertions.assertTrue;
4 4
 
5 5
 public class ROT13Test {
6 6
 

+ 12
- 0
SimpleCrypt.iml View File

@@ -0,0 +1,12 @@
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
+      <excludeFolder url="file://$MODULE_DIR$/target" />
8
+    </content>
9
+    <orderEntry type="inheritedJdk" />
10
+    <orderEntry type="sourceFolder" forTests="false" />
11
+  </component>
12
+</module>