소스 검색

parting is such sweet sorrow

rjsmall90 6 년 전
부모
커밋
aba3d84529
5개의 변경된 파일123개의 추가작업 그리고 32개의 파일을 삭제
  1. 0
    32
      Crypto/src/ROT13.java
  2. 16
    0
      SimpleCrypt.iml
  3. 11
    0
      pom.xml
  4. 69
    0
      src/main/java/ROT13.java
  5. 27
    0
      src/test/java/ROT13Test.java

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

+ 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$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
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.12" level="project" />
14
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 11
- 0
pom.xml 파일 보기

@@ -7,6 +7,17 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <properties>
11
+        <maven.compiler.source>1.8</maven.compiler.source>
12
+        <maven.compiler.target>1.8</maven.compiler.target>
13
+    </properties>
14
+    <dependencies>
15
+        <dependency>
16
+            <groupId>junit</groupId>
17
+            <artifactId>junit</artifactId>
18
+            <version>RELEASE</version>
19
+        </dependency>
20
+    </dependencies>
10 21
 
11 22
 
12 23
 </project>

+ 69
- 0
src/main/java/ROT13.java 파일 보기

@@ -0,0 +1,69 @@
1
+import java.io.File;
2
+import java.io.FileNotFoundException;
3
+import java.util.Scanner;
4
+
5
+import static java.lang.Character.isLowerCase;
6
+import static java.lang.Character.isUpperCase;
7
+import static java.lang.Character.toLowerCase;
8
+
9
+public class ROT13  {
10
+    private int shift;
11
+
12
+    ROT13(Character cs, Character cf) {
13
+        this.shift = cs-cf;
14
+    }
15
+
16
+    ROT13() {
17
+    }
18
+
19
+
20
+    public static String crypt(String text) throws UnsupportedOperationException {
21
+        char[] array = text.toCharArray();
22
+        StringBuilder build = new StringBuilder();
23
+        for(char x : array) {
24
+
25
+            char y = x;
26
+    if ((y >= 'a' && y <= 'm') || (y >= 'A' && y<= 'M')) {
27
+        y+=13;
28
+    } else if ((y  >= 'n' && y <= 'z') || (y >= 'M' && y<= 'Z')) {
29
+        y-=13;
30
+    }
31
+    build.append(y);
32
+}
33
+
34
+        return build.toString();
35
+    }
36
+
37
+    public static String encrypt(String text) {
38
+        return crypt(text);
39
+    }
40
+
41
+    public String decrypt(String text) {
42
+
43
+        return crypt(text);
44
+    }
45
+
46
+    public static String rotate(String s, Character c) {
47
+        String marine = s.substring(0, s.indexOf(c));
48
+        String sub = s.substring(s.indexOf(c));
49
+
50
+        return sub.concat(marine);
51
+    }
52
+
53
+    public static String encryptFile(String fileName) {
54
+        StringBuilder build = new StringBuilder();
55
+
56
+        File file = new File(fileName);
57
+        try(Scanner scan = new Scanner(file)) {
58
+
59
+            while(scan.hasNextLine()) {
60
+                String line = scan.nextLine();
61
+                String x = encrypt(line);
62
+                build.append(x+"\n");
63
+            }
64
+        } catch (FileNotFoundException e) {
65
+            e.printStackTrace();
66
+        }
67
+        return build.toString();
68
+    }
69
+}

Crypto/src/ROT13Test.java → src/test/java/ROT13Test.java 파일 보기

@@ -1,5 +1,7 @@
1 1
 import org.junit.Test;
2 2
 
3
+import java.io.File;
4
+
3 5
 import static org.junit.Assert.*;
4 6
 
5 7
 public class ROT13Test {
@@ -88,4 +90,29 @@ public class ROT13Test {
88 90
         assertTrue(actual.equals(Q1));
89 91
     }
90 92
 
93
+    @Test
94
+    public void testEncryptFile() {
95
+        File file = new File("sonnet18.txt");
96
+
97
+        String expected = ROT13.encrypt("Shall I compare thee to a summer’s day?\n" +
98
+                "Thou art more lovely and more temperate:\n" +
99
+                "Rough winds do shake the darling buds of May,\n" +
100
+                "And summer’s lease hath all too short a date;\n" +
101
+                "Sometime too hot the eye of heaven shines,\n" +
102
+                "And often is his gold complexion dimm'd;\n" +
103
+                "And every fair from fair sometime declines,\n" +
104
+                "By chance or nature’s changing course untrimm'd;\n" +
105
+                "But thy eternal summer shall not fade,\n" +
106
+                "Nor lose possession of that fair thou ow’st;\n" +
107
+                "Nor shall death brag thou wander’st in his shade,\n" +
108
+                "When in eternal lines to time thou grow’st:\n" +
109
+                "   So long as men can breathe or eyes can see,\n" +
110
+                "   So long lives this, and this gives life to thee.\n");
111
+
112
+        String actual = ROT13.encryptFile("sonnet18.txt");
113
+
114
+        assertEquals(expected, actual);
115
+
116
+    }
117
+
91 118
 }