Navya Sanal 6 年之前
父節點
當前提交
dc3aa474db
共有 4 個文件被更改,包括 72 次插入7 次删除
  1. 39
    7
      Crypto/src/ROT13.java
  2. 3
    0
      Crypto/src/ROT13Test.java
  3. 8
    0
      pom.xml
  4. 22
    0
      target/classes/Crypto.iml

+ 39
- 7
Crypto/src/ROT13.java 查看文件

@@ -1,27 +1,59 @@
1
+package src;
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
 
5 7
 public class ROT13  {
6 8
 
7
-    ROT13(Character cs, Character cf) {
9
+    int elementa;
10
+    public String crypt(String str)
11
+    {
12
+        String str1="";
13
+        for (int i = 0; i < str.length(); i++)
14
+        {
15
+            char ch = str.charAt(i);
16
+            if (ch >= 'A' && ch <= 'Z')
17
+            {
18
+                ch = (char) (ch + elementa);
19
+                if (ch > 'Z')
20
+                {
21
+                    ch = (char)(ch - 26);
22
+                }
23
+            }
24
+            else if (ch >= 'a' && ch <= 'z')
25
+            {
26
+                ch = (char)(ch + elementa);
27
+                if (ch > 'z')
28
+                {
29
+                    ch = (char)(ch - 26);
30
+                }
31
+            }
32
+            str1 = str1 + ch;
33
+        }
34
+        return str1;
8 35
     }
9 36
 
10
-    ROT13() {
11
-    }
12 37
 
13 38
 
14
-    public String crypt(String text) throws UnsupportedOperationException {
39
+    public ROT13(Character cs, Character cf) {
40
+        elementa = cf - cs;
15 41
 
16
-        return "";
17 42
     }
18 43
 
44
+    public ROT13() {
45
+        elementa=0;
46
+    }
47
+
48
+
49
+
19 50
     public String encrypt(String text) {
20
-        return text;
51
+       return crypt(text);
52
+
21 53
     }
22 54
 
23 55
     public String decrypt(String text) {
24
-        return text;
56
+        return crypt(text);
25 57
     }
26 58
 
27 59
     public static String rotate(String s, Character c) {

+ 3
- 0
Crypto/src/ROT13Test.java 查看文件

@@ -1,4 +1,7 @@
1
+package src;
2
+
1 3
 import org.junit.Test;
4
+import src.ROT13;
2 5
 
3 6
 import static org.junit.Assert.*;
4 7
 

+ 8
- 0
pom.xml 查看文件

@@ -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>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>compile</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>

+ 22
- 0
target/classes/Crypto.iml 查看文件

@@ -0,0 +1,22 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$">
6
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+    </content>
8
+    <orderEntry type="inheritedJdk" />
9
+    <orderEntry type="sourceFolder" forTests="false" />
10
+    <orderEntry type="library" name="Arquillian JUnit:Release" level="project" />
11
+    <orderEntry type="module-library">
12
+      <library name="JUnit4">
13
+        <CLASSES>
14
+          <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
15
+          <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
16
+        </CLASSES>
17
+        <JAVADOC />
18
+        <SOURCES />
19
+      </library>
20
+    </orderEntry>
21
+  </component>
22
+</module>