Browse Source

fixed encryption

Jennifer Chao 6 years ago
parent
commit
a3b18760ae
1 changed files with 18 additions and 11 deletions
  1. 18
    11
      LoopFun.java

+ 18
- 11
LoopFun.java View File

@@ -60,23 +60,30 @@ public class LoopFun
60 60
 
61 61
         char arr[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
62 62
 
63
-        int k;
64
-
65
-        for (int i = 0; i < 26; i++) {
63
+        for (int i = 0; i < word.length(); i++) {
64
+            for (int j = 0; j < 26; j++) {
65
+                if (word.charAt(i) == arr[j]){
66
+                    if (j < 23) {
67
+                        sbEncryption.append(arr[(j + 3)]);
68
+                    } else {
69
+                        continue;
70
+                    } 
71
+                }
72
+            }
73
+        }
74
+        
75
+         for (int i = 0; i < 26; i++) {
66 76
             for (int j = 0; j < word.length(); j++) {
67 77
                 if (word.charAt(j) == arr[i]){
68
-                    k = i;
69
-
70
-                    if (k < 23) {
71
-                        sbEncryption.append(arr[(k + 3)]);
72
-                    }
73
-                    
74
-                    if (k >= 23) {
75
-                        sbEncryption.append(arr[(k - 23)]);
78
+                    if (i >= 23) {
79
+                        sbEncryption.append(arr[(i - 23)]);
80
+                    } else {
81
+                        continue;
76 82
                     } 
77 83
                 }
78 84
             }
79 85
         }
86
+        
80 87
         String encryption = sbEncryption.toString();
81 88
 
82 89
         return encryption;