Browse Source

CRYPTO_LAB

Roy 6 years ago
parent
commit
4f4244225f
3 changed files with 50 additions and 6 deletions
  1. 27
    6
      Crypto/src/ROT13.java
  2. 15
    0
      SimpleCrypt.iml
  3. 8
    0
      pom.xml

+ 27
- 6
Crypto/src/ROT13.java View File

1
 import static java.lang.Character.isLowerCase;
1
 import static java.lang.Character.isLowerCase;
2
 import static java.lang.Character.isUpperCase;
2
 import static java.lang.Character.isUpperCase;
3
-import static java.lang.Character.toLowerCase;
3
+//import static java.lang.Character.toLowerCase;
4
 
4
 
5
 public class ROT13  {
5
 public class ROT13  {
6
+    private int shift;
6
 
7
 
7
     ROT13(Character cs, Character cf) {
8
     ROT13(Character cs, Character cf) {
9
+        this.shift = cf - cs;
8
     }
10
     }
9
 
11
 
10
     ROT13() {
12
     ROT13() {
13
+        this.shift = 13;
11
     }
14
     }
12
 
15
 
13
 
16
 
14
     public String crypt(String text) throws UnsupportedOperationException {
17
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
18
+        StringBuilder sb = new StringBuilder();
19
+        for(int i=0; i<text.length(); i++){
20
+            if(isLowerCase(text.charAt(i))){
21
+                sb.append((char)(((int)(text.charAt(i))+ shift - 97)%26+97));
22
+            }
23
+            else if(isUpperCase(text.charAt(i))){
24
+                sb.append((char)(((int)(text.charAt(i))+ shift - 65)%26+65));
25
+            }
26
+            else {
27
+                sb.append(text.charAt(i));
28
+            }
29
+        }
30
+
31
+        return sb.toString();
17
     }
32
     }
18
 
33
 
19
     public String encrypt(String text) {
34
     public String encrypt(String text) {
20
-        return text;
35
+
36
+        return crypt(text);
21
     }
37
     }
22
 
38
 
23
     public String decrypt(String text) {
39
     public String decrypt(String text) {
24
-        return text;
40
+
41
+
42
+        return crypt(text);
25
     }
43
     }
26
 
44
 
27
     public static String rotate(String s, Character c) {
45
     public static String rotate(String s, Character c) {
46
+        String subStr = s.substring(0, s.indexOf(c));
47
+        String subStr1 = s.substring(s.indexOf(c));
48
+
28
 
49
 
29
-        return "";
50
+        return subStr1.concat(subStr);
30
     }
51
     }
31
 
52
 
32
 }
53
 }

+ 15
- 0
SimpleCrypt.iml View File

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>

+ 8
- 0
pom.xml View File

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
+    <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
 </project>
20
 </project>