#3 SimpleCrypt

Открыто
Soujanya хочет смерджить 1 коммит(ов) из Soujanya/SimpleCrypt:master в master
4 измененных файлов: 58 добавлений и 18 удалений
  1. 35
    15
      Crypto/src/ROT13.java
  2. 0
    3
      Crypto/src/ROT13Test.java
  3. 15
    0
      SimpleCrypt.iml
  4. 8
    0
      pom.xml

+ 35
- 15
Crypto/src/ROT13.java Просмотреть файл

1
-import static java.lang.Character.isLowerCase;
2
-import static java.lang.Character.isUpperCase;
3
-import static java.lang.Character.toLowerCase;
4
-
5
-public class ROT13  {
1
+public class ROT13 {
2
+    private int shift;
6
 
3
 
7
     ROT13(Character cs, Character cf) {
4
     ROT13(Character cs, Character cf) {
5
+        this.shift = cs - cf;
8
     }
6
     }
9
 
7
 
10
     ROT13() {
8
     ROT13() {
9
+        this.shift = 13;
11
     }
10
     }
12
-
13
-
14
-    public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
11
+     /*   * ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the ROT13 class
12
+        * crypt("Why did the chicken cross the road?") should produce
13
+                "Jul qvq gur puvpxra pebff gur ebnq?"
14
+        * crypt("Gb trg gb gur bgure fvqr!") should produce "To get to the other side!"
15
+        * Make a constructor that takes two arguments to set the cipher correspondence. `ROT13 superSecure = new ROT13("a","m");`
16
+        * this defines the SHIFT of the two Character arrays.
17
+        * Caesar - make a subclass of ROT13 that implements the famous caesar cipher.
18
+        * Create you own cipher, using a different set of */
19
+
20
+     public String crypt(String text) throws UnsupportedOperationException {
21
+        StringBuilder builder = new StringBuilder();
22
+        char[] chars = text.toCharArray();
23
+        for (int i = 0; i < chars.length; i++) {
24
+            char c = text.charAt(i);
25
+            if (c >= 'a' && c <= 'm') {
26
+                c += 13;
27
+            } else if (c >= 'A' && c <= 'M') {
28
+                c += 13;
29
+            } else if (c >= 'n' && c <= 'z') {
30
+                c -= 13;
31
+            } else if (c >= 'N' && c <= 'Z') {
32
+                c -= 13;
33
+            }
34
+            builder.append(c);
35
+        }
36
+        return builder.toString();
17
     }
37
     }
18
 
38
 
19
     public String encrypt(String text) {
39
     public String encrypt(String text) {
20
-        return text;
40
+        return crypt(text);
21
     }
41
     }
22
 
42
 
23
     public String decrypt(String text) {
43
     public String decrypt(String text) {
24
-        return text;
44
+        return crypt(text);
25
     }
45
     }
26
 
46
 
27
     public static String rotate(String s, Character c) {
47
     public static String rotate(String s, Character c) {
28
-
29
-        return "";
48
+        String sub = s.substring(0, s.indexOf(c));
49
+        String sub1 = s.substring(s.indexOf(c));
50
+        return sub1.concat(sub);
30
     }
51
     }
31
-
32
 }
52
 }

+ 0
- 3
Crypto/src/ROT13Test.java Просмотреть файл

1
 import org.junit.Test;
1
 import org.junit.Test;
2
-
3
 import static org.junit.Assert.*;
2
 import static org.junit.Assert.*;
4
 
3
 
5
 public class ROT13Test {
4
 public class ROT13Test {
6
 
5
 
7
-
8
     @Test
6
     @Test
9
     public void rotateStringTest0() {
7
     public void rotateStringTest0() {
10
         // Given
8
         // Given
87
         // Then
85
         // Then
88
         assertTrue(actual.equals(Q1));
86
         assertTrue(actual.equals(Q1));
89
     }
87
     }
90
-
91
 }
88
 }

+ 15
- 0
SimpleCrypt.iml Просмотреть файл

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>

+ 8
- 0
pom.xml Просмотреть файл

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>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>compile</scope>
16
+        </dependency>
17
+    </dependencies>
10
 
18
 
11
 
19
 
12
 </project>
20
 </project>