#7 tkhong102

Abierta
tkhong102 desea fusionar 1 commits de tkhong102/SimpleCrypt:master en master
Se han modificado 4 ficheros con 58 adiciones y 14 borrados
  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 Ver fichero

10
     ROT13() {
10
     ROT13() {
11
     }
11
     }
12
 
12
 
13
-
14
     public String crypt(String text) throws UnsupportedOperationException {
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
     public String encrypt(String text) {
26
     public String encrypt(String text) {
20
-        return text;
27
+
28
+        return crypt(text);
21
     }
29
     }
22
 
30
 
23
     public String decrypt(String text) {
31
     public String decrypt(String text) {
24
-        return text;
32
+
33
+        return crypt(text);
25
     }
34
     }
26
 
35
 
27
     public static String rotate(String s, Character c) {
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 Ver fichero

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

+ 15
- 0
SimpleCrypt.iml Ver fichero

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 Ver fichero

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