shakila 6 年之前
父節點
當前提交
cdc3cc30cd
共有 3 個文件被更改,包括 42 次插入29 次删除
  1. 29
    25
      Crypto/src/ROT13.java
  2. 1
    4
      SimpleCrypt.iml
  3. 12
    0
      pom.xml

+ 29
- 25
Crypto/src/ROT13.java 查看文件

1
+import com.sun.xml.internal.fastinfoset.util.CharArray;
2
+
1
 import static java.lang.Character.isLowerCase;
3
 import static java.lang.Character.isLowerCase;
2
 import static java.lang.Character.isUpperCase;
4
 import static java.lang.Character.isUpperCase;
3
 import static java.lang.Character.toLowerCase;
5
 import static java.lang.Character.toLowerCase;
6
+
7
+import java.io.FileNotFoundException;
8
+import java.util.Scanner;
9
+import java.io.File;
4
 import java.lang.StringBuilder;
10
 import java.lang.StringBuilder;
5
 import java.lang.String;
11
 import java.lang.String;
6
 import java.lang.StringBuffer;
12
 import java.lang.StringBuffer;
19
 
25
 
20
     public String crypt(String text) throws UnsupportedOperationException {
26
     public String crypt(String text) throws UnsupportedOperationException {
21
         StringBuilder builder = new StringBuilder();
27
         StringBuilder builder = new StringBuilder();
22
-
23
-        for(int i = 0; i<text.length(); i++){
24
-            char c = text.charAt(i);
28
+        char[] charText = text.toCharArray();
29
+        for(char i: charText){
30
+            char c = i;
25
         if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
31
         if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
26
         else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
32
         else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
27
         builder.append(c);
33
         builder.append(c);
28
         }
34
         }
29
-    text = builder.toString();
30
 
35
 
31
-        return text;
36
+
37
+        return builder.toString();
32
     }
38
     }
33
 
39
 
34
     public String encrypt(String text) {
40
     public String encrypt(String text) {
35
-        for(int i = 0; i<text.length(); i++){
36
-            char ch = text.charAt(i);
37
-            if(ch>= 'A' && ch<='Z'){
38
-                ch = (char)(ch+13);
39
-                if (ch > 'Z') {
40
-                    ch = (char)(ch-26);
41
-                }
42
-            }
43
-            else if(ch>= 'a' && ch<='z'){
44
-                ch = (char)(ch+13);
45
-                if(ch>'z'){
46
-                    ch = (char)(ch-26);
47
-                }
48
-            }
49
-            cryptText = cryptText+ch;
50
-        }
51
-        text = cryptText;
52
-        return text;
41
+
42
+        return crypt(text);
53
     }
43
     }
54
 
44
 
55
     public String decrypt(String text) {
45
     public String decrypt(String text) {
56
-        encrypt(text);
57
-        return text;
46
+
47
+        return crypt(text);
58
     }
48
     }
59
 
49
 
60
     public static String rotate(String s, Character c) {
50
     public static String rotate(String s, Character c) {
65
 
55
 
66
     }
56
     }
67
 
57
 
58
+    public String encryptFile(String filename){
59
+        StringBuilder builder = new StringBuilder();
60
+        File file = new File(filename);
61
+        try (Scanner scanner = new Scanner (file)){
62
+            while (scanner.hasNextLine()){
63
+                String line = scanner.nextLine();
64
+                String xo = this.encrypt(line);
65
+                builder.append(xo+"/n");
66
+            }
67
+        } catch (FileNotFoundException e){
68
+            e.printStackTrace();
69
+        }
70
+        return builder.toString();
71
+    }
68
 }
72
 }

+ 1
- 4
SimpleCrypt.iml 查看文件

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
4
     <output url="file://$MODULE_DIR$/target/classes" />
4
     <output url="file://$MODULE_DIR$/target/classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
     <content url="file://$MODULE_DIR$">
6
     <content url="file://$MODULE_DIR$">
9
     </content>
9
     </content>
10
     <orderEntry type="inheritedJdk" />
10
     <orderEntry type="inheritedJdk" />
11
     <orderEntry type="sourceFolder" forTests="false" />
11
     <orderEntry type="sourceFolder" forTests="false" />
12
-    <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
13
-    <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.3.0-M1" level="project" />
14
-    <orderEntry type="library" name="Maven: org.testng:testng:6.14.3" level="project" />
15
     <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.0-M1" level="project" />
12
     <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.0-M1" level="project" />
16
     <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
13
     <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
17
     <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
14
     <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />

+ 12
- 0
pom.xml 查看文件

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>SimpleCrypt</artifactId>
8
     <artifactId>SimpleCrypt</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10
     <dependencies>
22
     <dependencies>
11
         <dependency>
23
         <dependency>
12
             <groupId>org.junit.jupiter</groupId>
24
             <groupId>org.junit.jupiter</groupId>