Bladeren bron

revereted back, attemtped caeser as well

Daniel Horowitz 6 jaren geleden
bovenliggende
commit
0fe0358a51
4 gewijzigde bestanden met toevoegingen van 73 en 8 verwijderingen
  1. 50
    7
      Crypto/src/ROT13.java
  2. 2
    1
      Crypto/tests/ROT13Test.java
  3. 14
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 50
- 7
Crypto/src/ROT13.java Bestand weergeven

@@ -1,8 +1,14 @@
1
+import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
2
+
1 3
 import static java.lang.Character.isLowerCase;
2 4
 import static java.lang.Character.isUpperCase;
3 5
 import static java.lang.Character.toLowerCase;
4 6
 
5
-public class ROT13  {
7
+public class ROT13 {
8
+
9
+    protected String alphaUp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
10
+    protected String alphaLow = "abcdefghijklmnopqrstuvwxyz";
11
+
6 12
 
7 13
     ROT13(Character cs, Character cf) {
8 14
     }
@@ -12,21 +18,58 @@ public class ROT13  {
12 18
 
13 19
 
14 20
     public String crypt(String text) throws UnsupportedOperationException {
21
+        StringBuilder simple = new StringBuilder();
22
+        for (int x = 0; x < text.length(); x++) {
23
+            char letter = text.charAt(x);
24
+            if (letter >= 'A' && letter <= 'M')
25
+                simple.append(letter += 13);
26
+            else if (letter >= 'N' && letter <= 'Z')
27
+                simple.append(letter -= 13);
28
+            else if (letter >= 'a' && letter <= 'm')
29
+                simple.append(letter += 13);
30
+            else if (letter >= 'n' && letter <= 'z')
31
+                simple.append(letter -= 13);
32
+            else
33
+                simple.append(letter);
34
+        }
15 35
 
16
-        return "";
36
+        return simple.toString();
17 37
     }
18 38
 
19 39
     public String encrypt(String text) {
20
-        return text;
40
+        return crypt(text);
21 41
     }
22 42
 
23 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) {
28 47
 
29
-        return "";
48
+    public static String rotate(String s, Character c) {
49
+        StringBuilder rotated = new StringBuilder();
50
+        int startIndex = s.indexOf(c);
51
+        rotated.append(s.substring(startIndex, s.length()));
52
+        rotated.append(s.substring(0, startIndex));
53
+        return rotated.toString();
30 54
     }
31 55
 
32
-}
56
+    public String createCipher(String upper, Character chooseUp, String lower, Character chooseLow, String input) {
57
+        String rotateUp = rotate(alphaUp, D);
58
+        String rotateLow = rotate(alphaLow, d);
59
+
60
+        StringBuilder ciphered = new StringBuilder();
61
+        for (int x = 0; x < input.length(); i++) {
62
+            char letter = input.charAt(0);
63
+            if (letter >= 'A' && letter <= 'Z')
64
+                ciphered.append(rotateUp.indexOf(letter));
65
+            else if (letter >= 'a' && letter <= 'z')
66
+                ciphered.append(rotateLow.indexOf(letter));
67
+            else return letter;
68
+
69
+
70
+        }
71
+
72
+        return ciphered.toString();
73
+
74
+    }
75
+}

Crypto/src/ROT13Test.java → Crypto/tests/ROT13Test.java Bestand weergeven

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Test;
2 3
 
3 4
 import static org.junit.Assert.*;
@@ -16,7 +17,7 @@ public class ROT13Test {
16 17
         String actual = cipher.rotate(s1, 'A');
17 18
 
18 19
         // Then
19
-        assertTrue(actual.equals(s2));
20
+        Assert.assertTrue(actual.equals(s2));
20 21
     }
21 22
 
22 23
     @Test

+ 14
- 0
SimpleCrypt.iml Bestand weergeven

@@ -0,0 +1,14 @@
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
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
12
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
13
+  </component>
14
+</module>

+ 7
- 0
pom.xml Bestand weergeven

@@ -7,6 +7,13 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+    </dependencies>
10 17
 
11 18
 
12 19
 </project>