瀏覽代碼

completed lab with no subclass beacuse it doesnt need one

mpierse 7 年之前
父節點
當前提交
0d23e35c5f
共有 1 個文件被更改,包括 5 次插入11 次删除
  1. 5
    11
      Crypto/src/ROT13.java

+ 5
- 11
Crypto/src/ROT13.java 查看文件

19
 
19
 
20
 
20
 
21
     public String crypt(String text) throws UnsupportedOperationException {
21
     public String crypt(String text) throws UnsupportedOperationException {
22
-    return text;
22
+      return encrypt(encrypt(text));
23
     }
23
     }
24
 
24
 
25
     public String encrypt(String text) {
25
     public String encrypt(String text) {
42
     }
42
     }
43
 
43
 
44
     public String decrypt(String text) {
44
     public String decrypt(String text) {
45
+
45
         String result = "";
46
         String result = "";
46
         int rotator = cf-cs;
47
         int rotator = cf-cs;
47
         boolean isUppercase = false;
48
         boolean isUppercase = false;
62
 
63
 
63
     public static String rotate(String s, Character c) {
64
     public static String rotate(String s, Character c) {
64
         String result = "";
65
         String result = "";
66
+        String reference = s+s;
65
         int rotator = Character.toLowerCase(c)-'a';
67
         int rotator = Character.toLowerCase(c)-'a';
66
         boolean isUppercase = false;
68
         boolean isUppercase = false;
67
         for(int i=0; i<s.length(); i++){
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
         return result;
73
         return result;
80
     }
74
     }