Yesoda Sanka 6 anos atrás
pai
commit
8bea18f769
3 arquivos alterados com 103 adições e 4 exclusões
  1. 80
    4
      Crypto/src/ROT13.java
  2. 15
    0
      SimpleCrypt.iml
  3. 8
    0
      pom.xml

+ 80
- 4
Crypto/src/ROT13.java Ver arquivo

@@ -1,32 +1,108 @@
1
+//package com.zipcodewilmington.simplecrypt;
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  {
8
+    /*
9
+     ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the ROT13 class
10
+  * crypt("Why did the chicken cross the road?") should produce "Jul qvq gur puvpxra pebff gur ebnq?"
11
+  * crypt("Gb trg gb gur bgure fvqr!") should produce "To get to the other side!"
12
+* Make a constructor that takes two arguments to set the cipher correspondence. `ROT13 superSecure = new ROT13("a","m");`
13
+  * this defines the SHIFT of the two Character arrays.
14
+* Caesar - make a subclass of ROT13 that implements the famous caesar cipher.
15
+* Create you own cipher, using a different set of
16
+     */
17
+     private int shift;
6 18
 
7 19
     ROT13(Character cs, Character cf) {
20
+        this.shift =cs-cf;
8 21
     }
9 22
 
10 23
     ROT13() {
24
+        shift=13;
11 25
     }
12 26
 
13 27
 
14 28
     public String crypt(String text) throws UnsupportedOperationException {
29
+        StringBuilder sb=new StringBuilder();
30
+        char[] ch=text.toCharArray();
31
+        for(int i=0;i<ch.length;i++ ) {
32
+            char c = text.charAt(i);
33
+            if (c >= 'a' && c <= 'm') {
34
+                c += 13;
35
+            } else if (c >= 'A' && c <= 'M') {
36
+                c += 13;
37
+            } else if (c >= 'n' && c <= 'z') {
38
+                c -= 13;
39
+            } else if (c >= 'N' && c <= 'Z') {
40
+                c-=13;
41
+            }
42
+            sb.append(c);
43
+        }
15 44
 
16
-        return "";
45
+        return  sb.toString() ;
17 46
     }
18 47
 
19 48
     public String encrypt(String text) {
20
-        return text;
49
+
50
+     /*   StringBuffer result= new StringBuffer();
51
+
52
+        for (int i=0; i<text.length(); i++)
53
+        {
54
+            if (Character.isUpperCase(text.charAt(i)))
55
+            {
56
+                char ch = (char)(((int)text.charAt(i) +
57
+                        13 - 65) % 26 + 65);
58
+                result.append(ch);
59
+                result.append(" ");
60
+            }
61
+            else
62
+            {
63
+                char ch = (char)(((int)text.charAt(i) +
64
+                        13 - 97) % 26 + 97);
65
+                result.append(ch);
66
+                result.append(" ");
67
+            }
68
+        }
69
+        return result.toString() ;*/
70
+        return crypt(text) ;
21 71
     }
22 72
 
23 73
     public String decrypt(String text) {
24
-        return text;
74
+       /* StringBuffer result= new StringBuffer();
75
+
76
+        for (int i=0; i<text.length(); i++)
77
+        {
78
+            if (Character.isUpperCase(text.charAt(i)))
79
+            {
80
+                char ch = (char)(((int)text.charAt(i) +
81
+                        13 - 65) % 26 + 65);
82
+                result.append(ch);
83
+            }
84
+            else
85
+            {
86
+                char ch = (char)(((int)text.charAt(i) +
87
+                        13 - 97) % 26 + 97);
88
+                result.append(ch);
89
+            }
90
+        }
91
+        return result.toString() ;*/
92
+       return crypt(text) ;
93
+
94
+
25 95
     }
26 96
 
27 97
     public static String rotate(String s, Character c) {
28 98
 
29
-        return "";
99
+       /*int n=s.indexOf(c);
100
+       String strPrefix =s.substring(n,s.length());
101
+       String strsuffix=s.substring(0,n-1);*/
102
+       String strPrefix=s.substring(0,s.indexOf(c) ) ;
103
+       String strsuffix =s.substring(s.indexOf(c) );
104
+
105
+        return strsuffix+strPrefix  ;
30 106
     }
31 107
 
32 108
 }

+ 15
- 0
SimpleCrypt.iml Ver arquivo

@@ -0,0 +1,15 @@
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 Ver arquivo

@@ -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>