Kaynağa Gözat

Merge 6f025f6e31738782b68222e80ad3774515ef58db into acdd71eb540bd8356719c3274bc7bbbdbd82ea21

amygdal 6 yıl önce
ebeveyn
işleme
22e90c6138
No account linked to committer's email
5 değiştirilmiş dosya ile 111 ekleme ve 6 silme
  1. 62
    4
      Crypto/src/ROT13.java
  2. 5
    2
      Crypto/src/ROT13Test.java
  3. 15
    0
      SimpleCrypt.iml
  4. 7
    0
      pom.xml
  5. 22
    0
      target/classes/Crypto.iml

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

@@ -1,10 +1,25 @@
1
+package 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;
4 6
 
5 7
 public class ROT13  {
6 8
 
9
+    private String myCipher;
10
+    private String myAlphabet;
11
+
12
+    public static void main(String[] args) {
13
+
14
+        System.out.println("0384");
15
+    }
16
+
7 17
     ROT13(Character cs, Character cf) {
18
+        myAlphabet = "abcdefghijklmnopqrstuvwxyz";
19
+        myCipher = rotate(myAlphabet,cf);
20
+        myAlphabet += myAlphabet.toUpperCase();
21
+        myCipher += myCipher.toUpperCase();
22
+
8 23
     }
9 24
 
10 25
     ROT13() {
@@ -13,20 +28,63 @@ public class ROT13  {
13 28
 
14 29
     public String crypt(String text) throws UnsupportedOperationException {
15 30
 
16
-        return "";
31
+        return encrypt(decrypt(text));
17 32
     }
18 33
 
19 34
     public String encrypt(String text) {
20
-        return text;
35
+
36
+        String encyrptedMessage = "";
37
+
38
+        for (int i = 0; i < text.length(); i++){
39
+            char charToRotate = text.charAt(i);
40
+            int indexOfCurrentStringLetter  = myAlphabet.indexOf(charToRotate);
41
+            if (indexOfCurrentStringLetter == -1){
42
+                encyrptedMessage+=charToRotate;
43
+            } else {
44
+                encyrptedMessage += Character.toString(myCipher.charAt(indexOfCurrentStringLetter));
45
+            }
46
+
47
+        }
48
+
49
+        return encyrptedMessage;
21 50
     }
22 51
 
23 52
     public String decrypt(String text) {
24
-        return text;
53
+
54
+        String decryptedMessage = "";
55
+
56
+        for (int i = 0; i < text.length(); i++){
57
+            char charToRotate = text.charAt(i);
58
+            int indexOfCurrentStringLetter  = myCipher.indexOf(charToRotate);
59
+            if (indexOfCurrentStringLetter == -1){
60
+                decryptedMessage+=charToRotate;
61
+            } else {
62
+                decryptedMessage += Character.toString(myAlphabet.charAt(indexOfCurrentStringLetter));
63
+            }
64
+
65
+
66
+        }
67
+
68
+        return decryptedMessage;
25 69
     }
26 70
 
27 71
     public static String rotate(String s, Character c) {
72
+//        int charIndex = 0;
28 73
 
29
-        return "";
74
+//       char[] charArray = s.toCharArray();
75
+//       for(int x = 0; x < charArray.length; x++){
76
+//           if (charArray[x] == c){
77
+//               charIndex = x;
78
+//           }
79
+//       }
80
+        int charIndex = s.indexOf(c);
81
+       String rightHalf = s.substring(charIndex);
82
+       String leftHalf = s.substring(0,charIndex);
83
+
84
+        return rightHalf + leftHalf;
30 85
     }
31 86
 
87
+
88
+
89
+
32 90
 }

+ 5
- 2
Crypto/src/ROT13Test.java Dosyayı Görüntüle

@@ -1,4 +1,7 @@
1
+package src;
2
+
1 3
 import org.junit.Test;
4
+import src.ROT13;
2 5
 
3 6
 import static org.junit.Assert.*;
4 7
 
@@ -64,14 +67,14 @@ public class ROT13Test {
64 67
         System.out.println(Q1);
65 68
         System.out.println(A1);
66 69
         // Then
67
-        assertTrue(actual.equals(A1));
70
+        assertEquals(A1, actual);
68 71
 
69 72
         // When
70 73
         String actual2 = cipher.decrypt(Q2);
71 74
         System.out.println(Q2);
72 75
         System.out.println(A2);
73 76
         // Then
74
-        assertTrue(actual2.equals(A2));
77
+        assertEquals(A2, actual2);
75 78
     }
76 79
     @Test
77 80
     public void cryptTest2() {

+ 15
- 0
SimpleCrypt.iml Dosyayı Görüntüle

@@ -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$/Crypto" 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 Dosyayı Görüntüle

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

+ 22
- 0
target/classes/Crypto.iml Dosyayı Görüntüle

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