#5 Completed Simple Crypt

Отворено
mpierse жели да споји 5 комит(е) из mpierse/SimpleCrypt:master у master
7 измењених фајлова са 75 додато и 7 уклоњено
  1. BIN
      .DS_Store
  2. BIN
      Crypto/.DS_Store
  3. 1
    1
      Crypto/Test/ROT13Test.java
  4. BIN
      Crypto/src/.DS_Store
  5. 50
    6
      Crypto/src/ROT13.java
  6. 16
    0
      SimpleCrypt.iml
  7. 8
    0
      pom.xml


Crypto/src/ROT13Test.java → Crypto/Test/ROT13Test.java Прегледај датотеку

14
         // When
14
         // When
15
         ROT13 cipher = new ROT13();
15
         ROT13 cipher = new ROT13();
16
         String actual = cipher.rotate(s1, 'A');
16
         String actual = cipher.rotate(s1, 'A');
17
-
18
         // Then
17
         // Then
19
         assertTrue(actual.equals(s2));
18
         assertTrue(actual.equals(s2));
20
     }
19
     }
28
         // When
27
         // When
29
         ROT13 cipher = new ROT13();
28
         ROT13 cipher = new ROT13();
30
         String actual = cipher.rotate(s1, 'D');
29
         String actual = cipher.rotate(s1, 'D');
30
+        System.out.println(actual);
31
 
31
 
32
         // Then
32
         // Then
33
         assertTrue(actual.equals(s2));
33
         assertTrue(actual.equals(s2));

BIN
Crypto/src/.DS_Store Прегледај датотеку


+ 50
- 6
Crypto/src/ROT13.java Прегледај датотеку

4
 
4
 
5
 public class ROT13  {
5
 public class ROT13  {
6
 
6
 
7
+    Character cs;
8
+    Character cf;
9
+
7
     ROT13(Character cs, Character cf) {
10
     ROT13(Character cs, Character cf) {
11
+        this.cs= cs;
12
+        this.cf=cf;
8
     }
13
     }
9
 
14
 
10
     ROT13() {
15
     ROT13() {
16
+        this.cs='a';
17
+        this.cf='m';
11
     }
18
     }
12
 
19
 
13
 
20
 
14
     public String crypt(String text) throws UnsupportedOperationException {
21
     public String crypt(String text) throws UnsupportedOperationException {
15
-
16
-        return "";
22
+      return encrypt(encrypt(text));
17
     }
23
     }
18
 
24
 
19
     public String encrypt(String text) {
25
     public String encrypt(String text) {
20
-        return text;
26
+        String result = "";
27
+        int rotator = cf-cs;
28
+        boolean isUppercase = false;
29
+        for(int i=0; i<text.length(); i++){
30
+            isUppercase = Character.isUpperCase(text.charAt(i));
31
+            int temp = Character.toLowerCase(text.charAt(i));
32
+            if (temp<97|temp>122){
33
+            } else if(temp+rotator < 122){
34
+            temp = (int)text.charAt(i)+rotator;
35
+            } else {
36
+                temp = 96 + ((temp+rotator)-122);
37
+            }
38
+            if(isUppercase){temp=Character.toUpperCase(temp);}
39
+            result+= (char)temp;
40
+        }
41
+        return result;
21
     }
42
     }
22
 
43
 
23
     public String decrypt(String text) {
44
     public String decrypt(String text) {
24
-        return text;
45
+
46
+        String result = "";
47
+        int rotator = cf-cs;
48
+        boolean isUppercase = false;
49
+        for(int i=0; i<text.length(); i++){
50
+            isUppercase = Character.isUpperCase(text.charAt(i));
51
+            int temp = Character.toLowerCase(text.charAt(i));
52
+            if (temp<97|temp>122){
53
+            } else if(temp-rotator > 97){
54
+                temp = (int)text.charAt(i)-rotator;
55
+            } else {
56
+                temp = 122 - (96-(temp-rotator));
57
+            }
58
+            if(isUppercase){temp=Character.toUpperCase(temp);}
59
+            result+= (char)temp;
60
+        }
61
+        return result;
25
     }
62
     }
26
 
63
 
27
     public static String rotate(String s, Character c) {
64
     public static String rotate(String s, Character c) {
28
-
29
-        return "";
65
+        String result = "";
66
+        String reference = s+s;
67
+        int rotator = Character.toLowerCase(c)-'a';
68
+        boolean isUppercase = false;
69
+        for(int i=0; i<s.length(); i++){
70
+          Character temp = reference.charAt(i+rotator);
71
+            result+= temp;
72
+        }
73
+        return result;
30
     }
74
     }
31
 
75
 
32
 }
76
 }

+ 16
- 0
SimpleCrypt.iml Прегледај датотеку

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/src" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/Crypto/Test" 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" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>

+ 8
- 0
pom.xml Прегледај датотеку

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>SimpleCrypt</artifactId>
8
     <artifactId>SimpleCrypt</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10
 
18
 
11
 
19
 
12
 </project>
20
 </project>