nafis nibir 6 年之前
父節點
當前提交
05a185e0f7
共有 3 個文件被更改,包括 76 次插入5 次删除
  1. 54
    5
      Crypto/src/ROT13.java
  2. 12
    0
      SimpleCrypt.iml
  3. 10
    0
      pom.xml

+ 54
- 5
Crypto/src/ROT13.java 查看文件

@@ -1,32 +1,81 @@
1
+import java.util.Arrays;
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
 
7
+
5 8
 public class ROT13  {
6 9
 
7 10
     ROT13(Character cs, Character cf) {
8 11
     }
9 12
 
10 13
     ROT13() {
14
+
11 15
     }
12 16
 
13 17
 
14 18
     public String crypt(String text) throws UnsupportedOperationException {
15 19
 
16
-        return "";
20
+        return encrypt(text);
17 21
     }
18 22
 
19 23
     public String encrypt(String text) {
20
-        return text;
24
+
25
+        //a - z is 97 - 122
26
+        //A - Z is 65 - 90
27
+        // get char value of c and store it as crypto
28
+        char c = 'n';
29
+        char cBig = 'N';
30
+        int cryptoLowerCase = (c - 97) % 26 ;
31
+        int cryptoUpperCase = (cBig - 65) % 26 ;
32
+
33
+        char[] arr = text.toCharArray();
34
+
35
+        for (int i = 0; i < arr.length; i++){
36
+            if (isLowerCase(arr[i])){
37
+                arr[i] = (char) ((int) arr[i] + cryptoLowerCase);
38
+                if (arr[i] > 'z'){
39
+                    arr[i] = (char) ((int) arr[i] - 26);
40
+                }
41
+            } else if (isUpperCase(arr[i])){
42
+                arr[i] = (char) ((int) arr[i] + cryptoUpperCase);
43
+                if (arr[i] > 'Z'){
44
+                    arr[i] = (char) ((int) arr[i] - 26);
45
+                }
46
+            }
47
+        }
48
+        String result = String.valueOf(arr);
49
+        return result;
21 50
     }
22 51
 
23 52
     public String decrypt(String text) {
24
-        return text;
53
+
54
+        return encrypt(text);
25 55
     }
26 56
 
57
+
27 58
     public static String rotate(String s, Character c) {
28 59
 
29
-        return "";
60
+//        char[] arr = s.toCharArray();
61
+//        int indexOfC = Arrays.asList(arr).indexOf(c);
62
+//
63
+//        while(indexOfC > 0) {
64
+//            for (int i = 1; i < s.length(); i++) {
65
+//                char temp = arr[i];
66
+//                arr[i] = arr[i + 1];
67
+//                arr[i+1] = temp;
68
+//            }
69
+//            indexOfC--;
70
+//        }
71
+//        String result = String.valueOf(arr);
72
+//        return result;
73
+
74
+        StringBuilder sb = new StringBuilder();
75
+        sb.append(s.substring(s.indexOf(c)));
76
+        sb.append(s.substring(0, s.indexOf(c)));
77
+        return sb.toString();
30 78
     }
31 79
 
32
-}
80
+
81
+}

+ 12
- 0
SimpleCrypt.iml 查看文件

@@ -0,0 +1,12 @@
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
+  </component>
12
+</module>

+ 10
- 0
pom.xml 查看文件

@@ -7,6 +7,16 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
10 11
 
12
+            <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
13
+            <dependency>
14
+                <groupId>org.apache.commons</groupId>
15
+                <artifactId>commons-lang3</artifactId>
16
+                <version>3.4</version>
17
+            </dependency>
18
+
19
+
20
+    </dependencies>
11 21
 
12 22
 </project>