shakila 6 gadus atpakaļ
vecāks
revīzija
5c8cd359cd
4 mainītis faili ar 83 papildinājumiem un 4 dzēšanām
  1. 38
    2
      Crypto/src/ROT13.java
  2. 2
    2
      Crypto/src/ROT13Test.java
  3. 23
    0
      SimpleCrypt.iml
  4. 20
    0
      pom.xml

+ 38
- 2
Crypto/src/ROT13.java Parādīt failu

@@ -1,8 +1,14 @@
1 1
 import static java.lang.Character.isLowerCase;
2 2
 import static java.lang.Character.isUpperCase;
3 3
 import static java.lang.Character.toLowerCase;
4
+import java.lang.StringBuilder;
5
+import java.lang.String;
6
+import java.lang.StringBuffer;
4 7
 
5 8
 public class ROT13  {
9
+   static int length = 0;
10
+   static int start = 0;
11
+   String cryptText = "";
6 12
 
7 13
     ROT13(Character cs, Character cf) {
8 14
     }
@@ -12,21 +18,51 @@ public class ROT13  {
12 18
 
13 19
 
14 20
     public String crypt(String text) throws UnsupportedOperationException {
21
+        StringBuilder builder = new StringBuilder();
15 22
 
16
-        return "";
23
+        for(int i = 0; i<text.length(); i++){
24
+            char c = text.charAt(i);
25
+        if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
26
+        else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
27
+        builder.append(c);
28
+        }
29
+    text = builder.toString();
30
+
31
+        return text;
17 32
     }
18 33
 
19 34
     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;
20 52
         return text;
21 53
     }
22 54
 
23 55
     public String decrypt(String text) {
56
+        encrypt(text);
24 57
         return text;
25 58
     }
26 59
 
27 60
     public static String rotate(String s, Character c) {
61
+        length = s.length();
62
+        start = s.indexOf(c);
63
+        int rotate = length - start;
64
+        return s.substring(start, length) + s.substring(0, start);
28 65
 
29
-        return "";
30 66
     }
31 67
 
32 68
 }

+ 2
- 2
Crypto/src/ROT13Test.java Parādīt failu

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

+ 23
- 0
SimpleCrypt.iml Parādīt failu

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

+ 20
- 0
pom.xml Parādīt failu

@@ -7,6 +7,26 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>SimpleCrypt</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>compile</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>org.testng</groupId>
19
+            <artifactId>testng</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>compile</scope>
22
+        </dependency>
23
+        <dependency>
24
+            <groupId>org.testng</groupId>
25
+            <artifactId>testng</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>compile</scope>
28
+        </dependency>
29
+    </dependencies>
10 30
 
11 31
 
12 32
 </project>