Kr Younger 6 vuotta sitten
vanhempi
commit
d0cbf69f27
4 muutettua tiedostoa jossa 152 lisäystä ja 3 poistoa
  1. 22
    0
      Crypto/Crypto.iml
  2. 32
    0
      Crypto/src/ROT13.java
  3. 91
    0
      Crypto/src/ROT13Test.java
  4. 7
    3
      README.md

+ 22
- 0
Crypto/Crypto.iml Näytä tiedosto

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

+ 32
- 0
Crypto/src/ROT13.java Näytä tiedosto

@@ -0,0 +1,32 @@
1
+import static java.lang.Character.isLowerCase;
2
+import static java.lang.Character.isUpperCase;
3
+import static java.lang.Character.toLowerCase;
4
+
5
+public class ROT13  {
6
+
7
+    ROT13(Character cs, Character cf) {
8
+    }
9
+
10
+    ROT13() {
11
+    }
12
+
13
+
14
+    public String crypt(String text) throws UnsupportedOperationException {
15
+
16
+        return "";
17
+    }
18
+
19
+    public String encrypt(String text) {
20
+        return text;
21
+    }
22
+
23
+    public String decrypt(String text) {
24
+        return text;
25
+    }
26
+
27
+    public static String rotate(String s, Character c) {
28
+
29
+        return "";
30
+    }
31
+
32
+}

+ 91
- 0
Crypto/src/ROT13Test.java Näytä tiedosto

@@ -0,0 +1,91 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class ROT13Test {
6
+
7
+
8
+    @Test
9
+    public void rotateStringTest0() {
10
+        // Given
11
+        String s1 = "ABCDEF";
12
+        String s2 = "ABCDEF";
13
+
14
+        // When
15
+        ROT13 cipher = new ROT13();
16
+        String actual = cipher.rotate(s1, 'A');
17
+
18
+        // Then
19
+        assertTrue(actual.equals(s2));
20
+    }
21
+
22
+    @Test
23
+    public void rotateStringTest1() {
24
+        // Given
25
+        String s1 = "ABCDEF";
26
+        String s2 = "DEFABC";
27
+
28
+        // When
29
+        ROT13 cipher = new ROT13();
30
+        String actual = cipher.rotate(s1, 'D');
31
+
32
+        // Then
33
+        assertTrue(actual.equals(s2));
34
+    }
35
+
36
+    @Test
37
+    public void rotateStringTest2() {
38
+        // Given
39
+        String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
40
+        String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM";
41
+
42
+        // When
43
+        ROT13 cipher = new ROT13();
44
+        String actual = cipher.rotate(s1, 'N');
45
+        System.out.println(s1);
46
+        System.out.println(actual);
47
+        // Then
48
+        assertTrue(actual.equals(s2));
49
+    }
50
+
51
+    @Test
52
+    public void cryptTest1() {
53
+        // Given
54
+        ROT13 cipher = new ROT13('a', 'n');
55
+
56
+        String Q1 = "Why did the chicken cross the road?";
57
+        String A1 = "Jul qvq gur puvpxra pebff gur ebnq?";
58
+
59
+        String Q2 = "Gb trg gb gur bgure fvqr!";
60
+        String A2 = "To get to the other side!";
61
+
62
+        // When
63
+        String actual = cipher.encrypt(Q1);
64
+        System.out.println(Q1);
65
+        System.out.println(A1);
66
+        // Then
67
+        assertTrue(actual.equals(A1));
68
+
69
+        // When
70
+        String actual2 = cipher.decrypt(Q2);
71
+        System.out.println(Q2);
72
+        System.out.println(A2);
73
+        // Then
74
+        assertTrue(actual2.equals(A2));
75
+    }
76
+    @Test
77
+    public void cryptTest2() {
78
+        // Given
79
+        ROT13 cipher = new ROT13('a', 'n');
80
+
81
+        String Q1 = "Why did the chicken cross the road?";
82
+        System.out.println(Q1);
83
+
84
+        // When
85
+        String actual = cipher.crypt(cipher.crypt(Q1));
86
+        System.out.println(actual);
87
+        // Then
88
+        assertTrue(actual.equals(Q1));
89
+    }
90
+
91
+}

+ 7
- 3
README.md Näytä tiedosto

@@ -28,24 +28,28 @@ ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle
28 28
 Applying ROT13 to a piece of text merely requires examining its alphabetic characters and replacing each one by the letter 13 places further along in the alphabet, wrapping back to the beginning if necessary.[3] A becomes N, B becomes O, and so on up to M, which becomes Z, then the sequence continues at the beginning of the alphabet: N becomes A, O becomes B, and so on to Z, which becomes M. Only those letters which occur in the English alphabet are affected; numbers, symbols, whitespace, and all other characters are left unchanged.
29 29
 
30 30
 ```Java
31
-String s = "we hold these truths to be self evident"
31
+String s = "we hold these truths to be self evident";
32
+
33
+//WHEN you create a ROT13 with 'a' and 'n' THEN 
32 34
 
33 35
 if (crypt(crypt(s)) == s) {
34 36
   return true;
35 37
 }
38
+
39
+//if anything else, you must use the encrypt/decrypt pair.
36 40
 ```
37 41
 In other words, two successive applications of ROT13 restore the original text (in mathematics, this is sometimes called an involution; in cryptography, a reciprocal cipher).
38 42
 
39 43
 The transformation can be done using a lookup table, such as the following:
40 44
 
41 45
 ```
42
-// for ROT13('a', 'm')
46
+// for ROT13('a', 'n')
43 47
 Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
44 48
 Output	NOPQRSTUVWXYZABCDEFGHIJKLM nopqrstuvwxyzabcdefghijklm
45 49
 
46 50
 // for ROT13('a', 'd')
47 51
 Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
48
-Output	EFGHIJKLMNOPQRSTUVWXYZABCD efghijklmnopqrstuvwxyzabcd
52
+Output	DEFGHIJKLMNOPQRSTUVWXYZABC defghijklmnopqrstuvwxyzabc
49 53
 ```
50 54
 For example, in the following joke, the punchline has been obscured by ROT13:
51 55