Browse Source

little progress

Nicholas Maidanos 6 years ago
parent
commit
08a636a7cf
5 changed files with 130 additions and 34 deletions
  1. 0
    32
      Crypto/src/ROT13.java
  2. 101
    0
      Crypto/src/main/java/ROT13.java
  3. 3
    2
      Crypto/src/test/java/ROT13Test.java
  4. 18
    0
      SimpleCrypt.iml
  5. 8
    0
      pom.xml

+ 0
- 32
Crypto/src/ROT13.java View File

@@ -1,32 +0,0 @@
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  {
6
-
7
-    ROT13(Character cs, Character cf) {
8
-    }
9
-
10
-    ROT13() {
11
-    }
12
-
13
-
14
-    public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
17
-    }
18
-
19
-    public String encrypt(String text) {
20
-        return text;
21
-    }
22
-
23
-    public String decrypt(String text) {
24
-        return text;
25
-    }
26
-
27
-    public static String rotate(String s, Character c) {
28
-
29
-        return "";
30
-    }
31
-
32
-}

+ 101
- 0
Crypto/src/main/java/ROT13.java View File

@@ -0,0 +1,101 @@
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  {
6
+
7
+    int rotateBy = 13;
8
+
9
+    private char[] rotatedAlphbet;
10
+    private char[] alphChars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
11
+
12
+    ROT13(Character cs, Character cf) {
13
+        rotateBy = numbersByCount(cs, cf);
14
+        rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz", cf).toCharArray();
15
+    }
16
+
17
+    ROT13() {}
18
+
19
+    public static int numbersByCount(Character cs, Character cf){
20
+        String alphabet = "abcdefghijklmnopqrstuvwxyz";
21
+        char[] alphChars = alphabet.toCharArray();
22
+
23
+        int counter = 0;
24
+        for(int i = 0; i < alphChars.length; i++){
25
+            if(counter == 0){
26
+                if(alphChars[i] == cs){
27
+                    counter++;
28
+                }
29
+            } else if(alphChars[i] != cf){
30
+                counter++;
31
+            } else{
32
+                break;
33
+            }
34
+        }
35
+        return counter;
36
+
37
+    }
38
+
39
+    public static void main(String[] args){
40
+        new ROT13('a','n');
41
+        //System.out.println(new ROT13().crypt("Gb trg gb gur bgure fvqr!"));
42
+    }
43
+
44
+    public String crypt(String text) throws UnsupportedOperationException {
45
+        StringBuilder sb = new StringBuilder();
46
+        char[] cars = text.toCharArray();
47
+
48
+        for(char car: cars){
49
+            if(Character.isLetter(car)){
50
+                if(Character.isUpperCase(car)){
51
+                    sb.append(Character.toUpperCase(charShift(car)));
52
+                }else {
53
+                    sb.append(charShift(car));
54
+                }
55
+            } else{
56
+                sb.append(car);
57
+            }
58
+
59
+        }
60
+        return sb.toString();
61
+
62
+    }
63
+
64
+    private Character charShift(char c){
65
+        Character car = null;
66
+        for(int i = 0; i < this.alphChars.length; i++) {
67
+            if(this.alphChars[i] == Character.toLowerCase(c)){
68
+                car = this.rotatedAlphbet[i];
69
+                break;
70
+            }
71
+        }
72
+        return car;
73
+    }
74
+
75
+    public String encrypt(String text) {
76
+        return this.crypt(text);
77
+    }
78
+
79
+    public String decrypt(String text) {
80
+
81
+        return this.crypt(text);
82
+    }
83
+
84
+    public static String rotate(String s, Character c) {
85
+        char[] cars = s.toCharArray();
86
+
87
+        char temp;
88
+        while(cars[0] != c){
89
+            temp = cars[0];
90
+            for(int i = 0; i < cars.length -1; i++){
91
+                cars[i] = cars[i +1];
92
+            }
93
+            cars[cars.length -1] = temp;
94
+        }
95
+
96
+        return new String(cars);
97
+    }
98
+
99
+
100
+
101
+}

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

@@ -1,6 +1,7 @@
1
-import org.junit.Test;
2 1
 
3
-import static org.junit.Assert.*;
2
+import org.junit.jupiter.api.Test;
3
+
4
+import static org.junit.jupiter.api.Assertions.assertTrue;
4 5
 
5 6
 public class ROT13Test {
6 7
 

+ 18
- 0
SimpleCrypt.iml View File

@@ -0,0 +1,18 @@
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/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.2.0" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
15
+    <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.2.0" level="project" />
17
+  </component>
18
+</module>

+ 8
- 0
pom.xml View File

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