Seth 7 лет назад
Родитель
Сommit
873875c145
6 измененных файлов: 86 добавлений и 46 удалений
  1. 0
    32
      Crypto/src/ROT13.java
  2. 47
    0
      Crypto/src/main/java/ROT13.java
  3. 1
    0
      Crypto/src/main/test/ROT13Test.java
  4. 14
    14
      README.md
  5. 16
    0
      SimpleCrypt.iml
  6. 8
    0
      pom.xml

+ 0
- 32
Crypto/src/ROT13.java Просмотреть файл

@@ -1,32 +0,0 @@
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
-}

+ 47
- 0
Crypto/src/main/java/ROT13.java Просмотреть файл

@@ -0,0 +1,47 @@
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
+    private final String upperCaseStart = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
7
+    private final String lowerCaseStart = "abcdefghijklmnopqrstuvwxyz";
8
+    protected String startUpper;
9
+    protected String startLower;
10
+    protected String registerUpper;
11
+    protected String registerLower;
12
+    private boolean symmetric = false;
13
+
14
+    public ROT13(Character cs, Character cf) {
15
+    }
16
+
17
+    public ROT13() {
18
+    }
19
+
20
+
21
+    public String crypt(String text) throws UnsupportedOperationException {
22
+        if (this.symmetric != true) throw new UnsupportedOperationException();
23
+
24
+        StringBuilder sb = new StringBuilder();
25
+        for (int i =0; i < text.length(); i++){
26
+            Character ch = text.charAt(i);
27
+            Integer position = 0;
28
+            if (isUpperCase(ch)){
29
+            }
30
+        }
31
+        return "";
32
+    }
33
+
34
+    public String encrypt(String text) {
35
+        return text;
36
+    }
37
+
38
+    public String decrypt(String text) {
39
+        return text;
40
+    }
41
+
42
+    public static String rotate(String s, Character c) {
43
+
44
+        return "";
45
+    }
46
+
47
+}

Crypto/src/ROT13Test.java → Crypto/src/main/test/ROT13Test.java Просмотреть файл

@@ -1,5 +1,6 @@
1 1
 import org.junit.Test;
2 2
 
3
+
3 4
 import static org.junit.Assert.*;
4 5
 
5 6
 public class ROT13Test {

+ 14
- 14
README.md Просмотреть файл

@@ -4,12 +4,12 @@ a simple set of crypt problems.
4 4
 ### Part 1
5 5
 Create a few ciphers. Use String inside of your classes.
6 6
 
7
-* ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the ROT13 class
7
+* java.ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the java.ROT13 class
8 8
   * crypt("Why did the chicken cross the road?") should produce "Jul qvq gur puvpxra pebff gur ebnq?"
9 9
   * crypt("Gb trg gb gur bgure fvqr!") should produce "To get to the other side!"
10
-* Make a constructor that takes two arguments to set the cipher correspondence. `ROT13 superSecure = new ROT13("a","m");`
10
+* Make a constructor that takes two arguments to set the cipher correspondence. `java.ROT13 superSecure = new java.ROT13("a","m");`
11 11
   * this defines the SHIFT of the two Character arrays.
12
-* Caesar - make a subclass of ROT13 that implements the famous caesar cipher.
12
+* Caesar - make a subclass of java.ROT13 that implements the famous caesar cipher.
13 13
 * Create you own cipher, using a different set of 
14 14
 
15 15
 ### Part 2
@@ -19,45 +19,45 @@ Prove that when you read in (sonnet18.enc), run the same crypt again, and prove
19 19
 
20 20
 ## Explanation
21 21
 
22
-ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in the alphabet. ROT13 is a special case of the Caesar cipher, developed in ancient Rome.
22
+java.ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in the alphabet. java.ROT13 is a special case of the Caesar cipher, developed in ancient Rome.
23 23
 
24
-Because there are 26 letters (2×13) in the basic Latin alphabet, ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.
24
+Because there are 26 letters (2×13) in the basic Latin alphabet, java.ROT13 is its own inverse; that is, to undo java.ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.
25 25
 
26
-ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle solutions, and offensive materials from the casual glance. ROT13 has been described as the "Usenet equivalent of a magazine printing the answer to a quiz upside down".[2] ROT13 has inspired a variety of letter and word games on-line, and is frequently mentioned in newsgroup conversations.
26
+java.ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle solutions, and offensive materials from the casual glance. java.ROT13 has been described as the "Usenet equivalent of a magazine printing the answer to a quiz upside down".[2] java.ROT13 has inspired a variety of letter and word games on-line, and is frequently mentioned in newsgroup conversations.
27 27
 
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.
28
+Applying java.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 31
 String s = "we hold these truths to be self evident";
32 32
 
33
-//WHEN you create a ROT13 with 'a' and 'n' THEN 
33
+java.ROT13
34 34
 
35
-if (crypt(crypt(s)) == s) {
35
+if (crypjava.ROT13pt(s)) == s) {
36 36
   return true;
37 37
 }
38 38
 
39 39
 //if anything else, you must use the encrypt/decrypt pair.
40 40
 ```
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).
41
+In other words, two successive applications of ROT13 restore the original text (in majava.ROT13tics, this is sometimes called an involution; in cryptography, a reciprocal cipher).
42 42
 
43 43
 The transformation can be done using a lookup table, such as the following:
44 44
 
45 45
 ```
46 46
 // for ROT13('a', 'n')
47
-Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
47
+Input	ABCDEFGHIJKLMNOPjava.ROT13VWXYZ abcdefghijklmnopqrstuvwxyz
48 48
 Output	NOPQRSTUVWXYZABCDEFGHIJKLM nopqrstuvwxyzabcdefghijklm
49 49
 
50 50
 // for ROT13('a', 'd')
51
-Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
51
+Input	ABCDEFGHIJKLMNOPjava.ROT13VWXYZ abcdefghijklmnopqrstuvwxyz
52 52
 Output	DEFGHIJKLMNOPQRSTUVWXYZABC defghijklmnopqrstuvwxyzabc
53 53
 ```
54 54
 For example, in the following joke, the punchline has been obscured by ROT13:
55 55
 
56 56
 ```
57
-Why did the chicken cross the road?
57
+Why did the chicken cross java.ROT13oad?
58 58
 Gb trg gb gur bgure fvqr!
59 59
 ```
60
-Transforming the entire text via ROT13 form, the answer to the joke is revealed:
60
+Transforming the entire text via ROT13 form, the answer to the joke is java.ROT13led:
61 61
 ```
62 62
 Jul qvq gur puvpxra pebff gur ebnq?
63 63
 To get to the other side!

+ 16
- 0
SimpleCrypt.iml Просмотреть файл

@@ -0,0 +1,16 @@
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_8">
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/main/test" isTestSource="true" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/src/main/java" isTestSource="false" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" name="Maven: junit:junit:4.13-beta-1" level="project" />
14
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

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