浏览代码

Merge 6a23698126ddbf65d1d31897da8f9de3300c9533 into acdd71eb540bd8356719c3274bc7bbbdbd82ea21

kbrinker1 6 年前
父节点
当前提交
425b9eee93
没有帐户链接到提交者的电子邮件

二进制
.DS_Store 查看文件


二进制
Crypto/.DS_Store 查看文件


+ 23
- 4
Crypto/src/ROT13.java 查看文件

@@ -1,3 +1,5 @@
1
+package Crypto.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;
@@ -12,16 +14,33 @@ public class ROT13  {
12 14
 
13 15
 
14 16
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
17
+        StringBuilder enigma = new StringBuilder();
18
+        for (int i = 0; i<text.length(); i++){
19
+            char coder = text.charAt(i);
20
+            if (coder >= 'A' && coder <= 'M'){
21
+                coder+=13;
22
+            }
23
+            else if (coder >= 'N' && coder <= 'Z'){
24
+                coder-=13;
25
+            }
26
+            else if (coder >= 'a' && coder <= 'm'){
27
+                coder+=13;
28
+            }
29
+            else if (coder >= 'n' && coder <= 'z'){
30
+                coder-=13;
31
+            }
32
+            enigma.append(coder);
33
+        }
34
+        return enigma.toString();
17 35
     }
18 36
 
19 37
     public String encrypt(String text) {
20
-        return text;
38
+
39
+        return crypt(text);
21 40
     }
22 41
 
23 42
     public String decrypt(String text) {
24
-        return text;
43
+        return crypt(text);
25 44
     }
26 45
 
27 46
     public static String rotate(String s, Character c) {

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

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

+ 15
- 0
SimpleCrypt.iml 查看文件

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

+ 7
- 0
pom.xml 查看文件

@@ -7,6 +7,13 @@
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
+        </dependency>
16
+    </dependencies>
10 17
 
11 18
 
12 19
 </project>

+ 24
- 0
target/classes/.gitignore 查看文件

@@ -0,0 +1,24 @@
1
+# Compiled class file
2
+*.class
3
+
4
+# Log file
5
+*.log
6
+
7
+# BlueJ files
8
+*.ctxt
9
+
10
+# Mobile Tools for Java (J2ME)
11
+.mtj.tmp/
12
+
13
+# Package Files #
14
+*.jar
15
+*.war
16
+*.ear
17
+*.zip
18
+*.tar.gz
19
+*.rar
20
+
21
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22
+hs_err_pid*
23
+
24
+.idea/

+ 22
- 0
target/classes/Crypto/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>

+ 21
- 0
target/classes/LICENSE 查看文件

@@ -0,0 +1,21 @@
1
+MIT License
2
+
3
+Copyright (c) 2018 KrYounger
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 65
- 0
target/classes/README.md 查看文件

@@ -0,0 +1,65 @@
1
+# SimpleCrypt
2
+a simple set of crypt problems.
3
+
4
+### Part 1
5
+Create a few ciphers. Use String inside of your classes.
6
+
7
+* ROT13 - take the 26 letters of the alphabet and create a `String <- crypt(String)` method in the ROT13 class
8
+  * crypt("Why did the chicken cross the road?") should produce "Jul qvq gur puvpxra pebff gur ebnq?"
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");`
11
+  * this defines the SHIFT of the two Character arrays.
12
+* Caesar - make a subclass of ROT13 that implements the famous caesar cipher.
13
+* Create you own cipher, using a different set of 
14
+
15
+### Part 2
16
+
17
+Make a method that reads a textfile (sonnet18.txt), encrypts it, and writes it back out to a different file (sonnet18.enc)
18
+Prove that when you read in (sonnet18.enc), run the same crypt again, and prove that it produces the same original text.
19
+
20
+## Explanation
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.
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.
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.
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.
29
+
30
+```Java
31
+String s = "we hold these truths to be self evident";
32
+
33
+//WHEN you create a ROT13 with 'a' and 'n' THEN 
34
+
35
+if (crypt(crypt(s)) == s) {
36
+  return true;
37
+}
38
+
39
+//if anything else, you must use the encrypt/decrypt pair.
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).
42
+
43
+The transformation can be done using a lookup table, such as the following:
44
+
45
+```
46
+// for ROT13('a', 'n')
47
+Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
48
+Output	NOPQRSTUVWXYZABCDEFGHIJKLM nopqrstuvwxyzabcdefghijklm
49
+
50
+// for ROT13('a', 'd')
51
+Input	ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
52
+Output	DEFGHIJKLMNOPQRSTUVWXYZABC defghijklmnopqrstuvwxyzabc
53
+```
54
+For example, in the following joke, the punchline has been obscured by ROT13:
55
+
56
+```
57
+Why did the chicken cross the road?
58
+Gb trg gb gur bgure fvqr!
59
+```
60
+Transforming the entire text via ROT13 form, the answer to the joke is revealed:
61
+```
62
+Jul qvq gur puvpxra pebff gur ebnq?
63
+To get to the other side!
64
+```
65
+

+ 15
- 0
target/classes/SimpleCrypt.iml 查看文件

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

+ 19
- 0
target/classes/pom.xml 查看文件

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington</groupId>
8
+    <artifactId>SimpleCrypt</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+    </dependencies>
17
+
18
+
19
+</project>

+ 14
- 0
target/classes/sonnet18.txt 查看文件

@@ -0,0 +1,14 @@
1
+Shall I compare thee to a summer’s day?
2
+Thou art more lovely and more temperate:
3
+Rough winds do shake the darling buds of May,
4
+And summer’s lease hath all too short a date;
5
+Sometime too hot the eye of heaven shines,
6
+And often is his gold complexion dimm'd;
7
+And every fair from fair sometime declines,
8
+By chance or nature’s changing course untrimm'd;
9
+But thy eternal summer shall not fade,
10
+Nor lose possession of that fair thou ow’st;
11
+Nor shall death brag thou wander’st in his shade,
12
+When in eternal lines to time thou grow’st:
13
+   So long as men can breathe or eyes can see,
14
+   So long lives this, and this gives life to thee.