Parcourir la source

completed lab with no subclass beacuse it doesnt need one

mpierse il y a 7 ans
Parent
révision
0d23e35c5f
1 fichiers modifiés avec 5 ajouts et 11 suppressions
  1. 5
    11
      Crypto/src/ROT13.java

+ 5
- 11
Crypto/src/ROT13.java Voir le fichier

@@ -19,7 +19,7 @@ public class ROT13  {
19 19
 
20 20
 
21 21
     public String crypt(String text) throws UnsupportedOperationException {
22
-    return text;
22
+      return encrypt(encrypt(text));
23 23
     }
24 24
 
25 25
     public String encrypt(String text) {
@@ -42,6 +42,7 @@ public class ROT13  {
42 42
     }
43 43
 
44 44
     public String decrypt(String text) {
45
+
45 46
         String result = "";
46 47
         int rotator = cf-cs;
47 48
         boolean isUppercase = false;
@@ -62,19 +63,12 @@ public class ROT13  {
62 63
 
63 64
     public static String rotate(String s, Character c) {
64 65
         String result = "";
66
+        String reference = s+s;
65 67
         int rotator = Character.toLowerCase(c)-'a';
66 68
         boolean isUppercase = false;
67 69
         for(int i=0; i<s.length(); i++){
68
-            isUppercase = Character.isUpperCase(s.charAt(i));
69
-            int temp = Character.toLowerCase(s.charAt(i));
70
-            if (temp<97|temp>122){
71
-            } else if(temp+rotator < 122){
72
-                temp = s.charAt(i)+rotator;
73
-            } else {
74
-                temp = 96 + ((temp+rotator)-122);
75
-            }
76
-            if(isUppercase){temp=Character.toUpperCase(temp);}
77
-            result+= (char)temp;
70
+          Character temp = reference.charAt(i+rotator);
71
+            result+= temp;
78 72
         }
79 73
         return result;
80 74
     }