Bo Lee 6 years ago
parent
commit
9d75d76eee
5 changed files with 72 additions and 4 deletions
  1. 5
    0
      Crypto/src/Caesar.java
  2. 44
    4
      Crypto/src/ROT13.java
  3. 0
    0
      Crypto/test/ROT13Test.java
  4. 16
    0
      SimpleCrypt.iml
  5. 7
    0
      pom.xml

+ 5
- 0
Crypto/src/Caesar.java View File

@@ -0,0 +1,5 @@
1
+public class Caesar extends ROT13 {
2
+    Caesar(Character cs, Character cf) {
3
+        super('a', 'd');
4
+    }
5
+}

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

@@ -12,21 +12,61 @@ public class ROT13  {
12 12
 
13 13
 
14 14
     public String crypt(String text) throws UnsupportedOperationException {
15
+        StringBuilder sb = new StringBuilder();
16
+        for (int i = 0; i < text.length(); i++) {
17
+            char c = text.charAt(i);
18
+            if (c >= 'a' && c <= 'm'){
19
+                c +=13;
20
+            }
21
+            else if (c >= 'A' && c <= 'M'){
22
+                c +=13;
23
+            }
24
+            else if (c >= 'n' && c <= 'z'){
25
+                c -=13;
26
+            }
27
+            else if (c >= 'N' && c <= 'Z'){
28
+                c -=13;
29
+            }
30
+            sb.append(c);
15 31
 
16
-        return "";
32
+        }
33
+        return sb.toString();
17 34
     }
18 35
 
19 36
     public String encrypt(String text) {
20
-        return text;
37
+        return crypt(text);
21 38
     }
22 39
 
23 40
     public String decrypt(String text) {
24
-        return text;
41
+        return crypt(text);
25 42
     }
26 43
 
27 44
     public static String rotate(String s, Character c) {
45
+// take string and split and reutrn
46
+        StringBuilder sb = new StringBuilder();
47
+        sb.append(s.substring(s.indexOf(c)));
48
+        sb.append(s.substring(0, s.indexOf(c)));
49
+        return sb.toString();
50
+    }
51
+
52
+    String sonnet18 = "Shall I compare thee to a summer’s day?\n" +
53
+            "Thou art more lovely and more temperate:\n" +
54
+            "Rough winds do shake the darling buds of May,\n" +
55
+            "And summer’s lease hath all too short a date;\n" +
56
+            "Sometime too hot the eye of heaven shines,\n" +
57
+            "And often is his gold complexion dimm'd;\n" +
58
+            "And every fair from fair sometime declines,\n" +
59
+            "By chance or nature’s changing course untrimm'd;\n" +
60
+            "But thy eternal summer shall not fade,\n" +
61
+            "Nor lose possession of that fair thou ow’st;\n" +
62
+            "Nor shall death brag thou wander’st in his shade,\n" +
63
+            "When in eternal lines to time thou grow’st:\n" +
64
+            "   So long as men can breathe or eyes can see,\n" +
65
+            "   So long lives this, and this gives life to thee.\n";
66
+
67
+    public String cryptSonnet (String sonnet ) {
68
+        return crypt(sonnet18);
28 69
 
29
-        return "";
30 70
     }
31 71
 
32 72
 }

Crypto/src/ROT13Test.java → Crypto/test/ROT13Test.java View File


+ 16
- 0
SimpleCrypt.iml View File

@@ -0,0 +1,16 @@
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/test" isTestSource="true" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/src" isTestSource="false" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 7
- 0
pom.xml View File

@@ -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>