mpierse 7 лет назад
Родитель
Сommit
f707c9b370
2 измененных файлов: 26 добавлений и 5 удалений
  1. 1
    1
      Crypto/Test/ROT13Test.java
  2. 25
    4
      Crypto/src/ROT13.java

+ 1
- 1
Crypto/Test/ROT13Test.java Просмотреть файл

@@ -61,7 +61,7 @@ public class ROT13Test {
61 61
 
62 62
         // When
63 63
         String actual = cipher.encrypt(Q1);
64
-        System.out.println(Q1);
64
+        System.out.println(actual);
65 65
         System.out.println(A1);
66 66
         // Then
67 67
         assertTrue(actual.equals(A1));

+ 25
- 4
Crypto/src/ROT13.java Просмотреть файл

@@ -19,16 +19,37 @@ public class ROT13  {
19 19
 
20 20
 
21 21
     public String crypt(String text) throws UnsupportedOperationException {
22
-
23
-        return "";
22
+    return text;
24 23
     }
25 24
 
26 25
     public String encrypt(String text) {
27
-        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==32){
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){Character.toUpperCase(temp);}
39
+            result+= (char)temp;
40
+        }
41
+        return result;
28 42
     }
29 43
 
30 44
     public String decrypt(String text) {
31
-        return text;
45
+        String result = "";
46
+        int temp = 0;
47
+        int rotator = cf-cs;
48
+        for(int i=0; i<text.length(); i++){
49
+            temp = (int)text.charAt(i)-rotator;
50
+            result+= (char)temp;
51
+        }
52
+        return result;
32 53
     }
33 54
 
34 55
     public static String rotate(String s, Character c) {