Jessica Campbell пре 6 година
родитељ
комит
ba4ca8a2ae
4 измењених фајлова са 72 додато и 9 уклоњено
  1. 7
    0
      Crypto/src/CaesarCipher.java
  2. 43
    9
      Crypto/src/ROT13.java
  3. 15
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml

+ 7
- 0
Crypto/src/CaesarCipher.java Прегледај датотеку

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

+ 43
- 9
Crypto/src/ROT13.java Прегледај датотеку

@@ -10,23 +10,57 @@ public class ROT13  {
10 10
     ROT13() {
11 11
     }
12 12
 
13
+//    public String shift13(String str, Character ch) {
14
+//        StringBuilder shifted = new StringBuilder();
15
+//        Character[] strToArray = new Character[0];
16
+//        for (int i = 0; i < strToArray.length; i++) {
17
+//            if (i >= 97 && i <= 122) {
18
+//                i += 13;
19
+//                shifted.append(i);
20
+//            }
21
+//            if (i <= 90 && i >= 65) {
22
+//                i += 13;
23
+//                shifted.append(i);
24
+//            } else {
25
+//                shifted.append(i);
26
+//            }
27
+//        }
28
+//        return shifted.toString();
29
+//    }
13 30
 
14
-    public String crypt(String text) throws UnsupportedOperationException {
15 31
 
16
-        return "";
32
+    public String crypt(String text) throws UnsupportedOperationException {
33
+        StringBuilder sb = new StringBuilder();
34
+        for (int i = 0; i < text.length(); i++) {
35
+            char c= text.charAt(i);
36
+            if (c >= 'a' && c <= 'm') {
37
+                c += 13;
38
+            } else if (c >= 'A' && c <= 'M') {
39
+                c += 13;
40
+            } else if (c >= 'n' && c <= 'z') {
41
+                c -= 13;
42
+            } else if (c >= 'N' && c <= 'Z') {
43
+                c -= 13;
44
+            }
45
+            sb.append(c);
46
+        }
47
+        return sb.toString();
17 48
     }
18 49
 
19
-    public String encrypt(String text) {
20
-        return text;
50
+    public String encrypt (String text){
51
+        return crypt(text);
21 52
     }
22 53
 
23
-    public String decrypt(String text) {
24
-        return text;
54
+    public String decrypt (String text){
55
+        return crypt(text);
25 56
     }
26 57
 
27
-    public static String rotate(String s, Character c) {
28
-
29
-        return "";
58
+    public static String rotate (String s, Character c){
59
+        int startIndex = s.indexOf(c);
60
+        StringBuilder sb = new StringBuilder();
61
+        sb.append(s.substring(startIndex, s.length()));
62
+        sb.append(s.substring(0, startIndex));
63
+        return sb.toString();
30 64
     }
31 65
 
32 66
 }

+ 15
- 0
SimpleCrypt.iml Прегледај датотеку

@@ -0,0 +1,15 @@
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 Прегледај датотеку

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