#22 shakila3

Otwarty
shakila3 chce scalić 2 commity/ów z shakila3/ZCW-SimpleCrypt0:master do master
4 zmienionych plików z 98 dodań i 6 usunięć
  1. 44
    4
      Crypto/src/ROT13.java
  2. 2
    2
      Crypto/src/ROT13Test.java
  3. 20
    0
      SimpleCrypt.iml
  4. 32
    0
      pom.xml

+ 44
- 4
Crypto/src/ROT13.java Wyświetl plik

@@ -1,8 +1,20 @@
1
+import com.sun.xml.internal.fastinfoset.util.CharArray;
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
 
7
+import java.io.FileNotFoundException;
8
+import java.util.Scanner;
9
+import java.io.File;
10
+import java.lang.StringBuilder;
11
+import java.lang.String;
12
+import java.lang.StringBuffer;
13
+
5 14
 public class ROT13  {
15
+   static int length = 0;
16
+   static int start = 0;
17
+   String cryptText = "";
6 18
 
7 19
     ROT13(Character cs, Character cf) {
8 20
     }
@@ -12,21 +24,49 @@ public class ROT13  {
12 24
 
13 25
 
14 26
     public String crypt(String text) throws UnsupportedOperationException {
27
+        StringBuilder builder = new StringBuilder();
28
+        char[] charText = text.toCharArray();
29
+        for(char i: charText){
30
+            char c = i;
31
+        if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
32
+        else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
33
+        builder.append(c);
34
+        }
35
+
15 36
 
16
-        return "";
37
+        return builder.toString();
17 38
     }
18 39
 
19 40
     public String encrypt(String text) {
20
-        return text;
41
+
42
+        return crypt(text);
21 43
     }
22 44
 
23 45
     public String decrypt(String text) {
24
-        return text;
46
+
47
+        return crypt(text);
25 48
     }
26 49
 
27 50
     public static String rotate(String s, Character c) {
51
+        length = s.length();
52
+        start = s.indexOf(c);
53
+        int rotate = length - start;
54
+        return s.substring(start, length) + s.substring(0, start);
28 55
 
29
-        return "";
30 56
     }
31 57
 
58
+    public String encryptFile(String filename){
59
+        StringBuilder builder = new StringBuilder();
60
+        File file = new File(filename);
61
+        try (Scanner scanner = new Scanner (file)){
62
+            while (scanner.hasNextLine()){
63
+                String line = scanner.nextLine();
64
+                String xo = this.encrypt(line);
65
+                builder.append(xo+"/n");
66
+            }
67
+        } catch (FileNotFoundException e){
68
+            e.printStackTrace();
69
+        }
70
+        return builder.toString();
71
+    }
32 72
 }

+ 2
- 2
Crypto/src/ROT13Test.java Wyświetl plik

@@ -1,6 +1,6 @@
1
-import org.junit.Test;
1
+import org.testng.annotations.Test;
2 2
 
3
-import static org.junit.Assert.*;
3
+import static org.junit.jupiter.api.Assertions.assertTrue;
4 4
 
5 5
 public class ROT13Test {
6 6
 

+ 20
- 0
SimpleCrypt.iml Wyświetl plik

@@ -0,0 +1,20 @@
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_7">
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: org.junit.jupiter:junit-jupiter-api:5.3.0-M1" level="project" />
13
+    <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
14
+    <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
15
+    <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.3.0-M1" level="project" />
16
+    <orderEntry type="library" name="Maven: org.testng:testng:6.14.3" level="project" />
17
+    <orderEntry type="library" name="Maven: com.beust:jcommander:1.72" level="project" />
18
+    <orderEntry type="library" name="Maven: org.apache-extras.beanshell:bsh:2.0b6" level="project" />
19
+  </component>
20
+</module>

+ 32
- 0
pom.xml Wyświetl plik

@@ -7,6 +7,38 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>org.junit.jupiter</groupId>
25
+            <artifactId>junit-jupiter-api</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>compile</scope>
28
+        </dependency>
29
+        <dependency>
30
+            <groupId>org.testng</groupId>
31
+            <artifactId>testng</artifactId>
32
+            <version>RELEASE</version>
33
+            <scope>compile</scope>
34
+        </dependency>
35
+        <dependency>
36
+            <groupId>org.testng</groupId>
37
+            <artifactId>testng</artifactId>
38
+            <version>RELEASE</version>
39
+            <scope>compile</scope>
40
+        </dependency>
41
+    </dependencies>
10 42
 
11 43
 
12 44
 </project>