Browse Source

test case passed

Aleena Rose-Mathew 6 years ago
parent
commit
5d1ad93727
3 changed files with 53 additions and 13 deletions
  1. 30
    10
      Crypto/src/ROT13.java
  2. 3
    2
      Crypto/src/ROT13Test.java
  3. 20
    1
      pom.xml

+ 30
- 10
Crypto/src/ROT13.java View File

1
-import static java.lang.Character.isLowerCase;
2
-import static java.lang.Character.isUpperCase;
3
-import static java.lang.Character.toLowerCase;
4
 
1
 
5
 public class ROT13  {
2
 public class ROT13  {
6
 
3
 
4
+    Integer diff;
7
     ROT13(Character cs, Character cf) {
5
     ROT13(Character cs, Character cf) {
6
+        this.diff=Math.abs((int)cs-(int)cf);
7
+
8
     }
8
     }
9
 
9
 
10
     ROT13() {
10
     ROT13() {
12
 
12
 
13
 
13
 
14
     public String crypt(String text) throws UnsupportedOperationException {
14
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
15
+        String str="";
16
+
17
+        for (int i=0; i<text.length(); i++)
18
+        {
19
+            if(!Character.isLetter(text.charAt(i)))
20
+            {
21
+                str+=text.charAt(i);
22
+            }
23
+            else if (Character.isUpperCase(text.charAt(i)))
24
+            {
25
+                char ch = (char)(((int)text.charAt(i) + diff - 65) % 26 + 65);
26
+                str+=ch;
27
+            }
28
+            else if(Character.isLowerCase(text.charAt(i)))
29
+            {
30
+                char ch = (char)(((int)text.charAt(i) + diff - 97) % 26 + 97);
31
+                str+=ch;
32
+            }
33
+        }
34
+        return str;
17
     }
35
     }
18
 
36
 
19
     public String encrypt(String text) {
37
     public String encrypt(String text) {
20
-        return text;
38
+
39
+        return crypt(text);
21
     }
40
     }
22
 
41
 
23
     public String decrypt(String text) {
42
     public String decrypt(String text) {
24
-        return text;
43
+        return crypt(text);
25
     }
44
     }
26
 
45
 
27
-    public static String rotate(String s, Character c) {
28
-
29
-        return "";
46
+    public static String rotate(String string, Character c)
47
+    {
48
+        Integer diff=(int)c-(int)'A';
49
+        return string.substring(diff,string.length())+string.substring(0,diff);
30
     }
50
     }
31
 
51
 
32
 }
52
 }

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

1
-import org.junit.Test;
2
 
1
 
3
-import static org.junit.Assert.*;
2
+import org.testng.annotations.Test;
3
+import static org.testng.Assert.assertTrue;
4
 
4
 
5
 public class ROT13Test {
5
 public class ROT13Test {
6
 
6
 
63
         String actual = cipher.encrypt(Q1);
63
         String actual = cipher.encrypt(Q1);
64
         System.out.println(Q1);
64
         System.out.println(Q1);
65
         System.out.println(A1);
65
         System.out.println(A1);
66
+        System.out.println(actual);
66
         // Then
67
         // Then
67
         assertTrue(actual.equals(A1));
68
         assertTrue(actual.equals(A1));
68
 
69
 

+ 20
- 1
pom.xml View File

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
-
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>org.junit.jupiter</groupId>
19
+            <artifactId>junit-jupiter-api</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+        <dependency>
24
+            <groupId>org.testng</groupId>
25
+            <artifactId>testng</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>compile</scope>
28
+        </dependency>
29
+    </dependencies>
11
 
30
 
12
 </project>
31
 </project>