shakila 6 yıl önce
ebeveyn
işleme
cdc3cc30cd
3 değiştirilmiş dosya ile 42 ekleme ve 29 silme
  1. 29
    25
      Crypto/src/ROT13.java
  2. 1
    4
      SimpleCrypt.iml
  3. 12
    0
      pom.xml

+ 29
- 25
Crypto/src/ROT13.java Dosyayı Görüntüle

@@ -1,6 +1,12 @@
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;
6
+
7
+import java.io.FileNotFoundException;
8
+import java.util.Scanner;
9
+import java.io.File;
4 10
 import java.lang.StringBuilder;
5 11
 import java.lang.String;
6 12
 import java.lang.StringBuffer;
@@ -19,42 +25,26 @@ public class ROT13  {
19 25
 
20 26
     public String crypt(String text) throws UnsupportedOperationException {
21 27
         StringBuilder builder = new StringBuilder();
22
-
23
-        for(int i = 0; i<text.length(); i++){
24
-            char c = text.charAt(i);
28
+        char[] charText = text.toCharArray();
29
+        for(char i: charText){
30
+            char c = i;
25 31
         if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
26 32
         else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
27 33
         builder.append(c);
28 34
         }
29
-    text = builder.toString();
30 35
 
31
-        return text;
36
+
37
+        return builder.toString();
32 38
     }
33 39
 
34 40
     public String encrypt(String text) {
35
-        for(int i = 0; i<text.length(); i++){
36
-            char ch = text.charAt(i);
37
-            if(ch>= 'A' && ch<='Z'){
38
-                ch = (char)(ch+13);
39
-                if (ch > 'Z') {
40
-                    ch = (char)(ch-26);
41
-                }
42
-            }
43
-            else if(ch>= 'a' && ch<='z'){
44
-                ch = (char)(ch+13);
45
-                if(ch>'z'){
46
-                    ch = (char)(ch-26);
47
-                }
48
-            }
49
-            cryptText = cryptText+ch;
50
-        }
51
-        text = cryptText;
52
-        return text;
41
+
42
+        return crypt(text);
53 43
     }
54 44
 
55 45
     public String decrypt(String text) {
56
-        encrypt(text);
57
-        return text;
46
+
47
+        return crypt(text);
58 48
     }
59 49
 
60 50
     public static String rotate(String s, Character c) {
@@ -65,4 +55,18 @@ public class ROT13  {
65 55
 
66 56
     }
67 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
+    }
68 72
 }

+ 1
- 4
SimpleCrypt.iml Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
4 4
     <output url="file://$MODULE_DIR$/target/classes" />
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
@@ -9,9 +9,6 @@
9 9
     </content>
10 10
     <orderEntry type="inheritedJdk" />
11 11
     <orderEntry type="sourceFolder" forTests="false" />
12
-    <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
13
-    <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.3.0-M1" level="project" />
14
-    <orderEntry type="library" name="Maven: org.testng:testng:6.14.3" level="project" />
15 12
     <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.0-M1" level="project" />
16 13
     <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
17 14
     <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />

+ 12
- 0
pom.xml Dosyayı Görüntüle

@@ -7,6 +7,18 @@
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>
10 22
     <dependencies>
11 23
         <dependency>
12 24
             <groupId>org.junit.jupiter</groupId>