-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.java
More file actions
37 lines (35 loc) · 1.33 KB
/
Copy pathEncryption.java
File metadata and controls
37 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Encryption {
private static final int SHIFT = 3;
private static char[] charAtI;
private static char charAtO;
public static String encrypt(String input) {
String encrypted = input;
String theDecryptedString="";
charAtI = encrypted.toCharArray();
for (int i = 0; i < encrypted.length(); i++) {
charAtO = encrypted.charAt(i);
charAtI[i] = (char)(charAtO + SHIFT);
System.out.println((char) (charAtO+SHIFT));
}
for (int i = 0; i < encrypted.length(); i++) {
theDecryptedString = (String) ( theDecryptedString + charAtI[i]);
}
System.out.println(theDecryptedString);
return theDecryptedString;
}
public static String decrypt(String input) {
String decrypted = input;
String theDecryptedString="";
charAtI = decrypted.toCharArray();
for (int i = 0; i < decrypted.length(); i++) {
charAtO = decrypted.charAt(i);
charAtI[i] = (char)(charAtO - SHIFT);
System.out.println((char) (charAtO-SHIFT));
}
for (int i = 0; i < decrypted.length(); i++) {
theDecryptedString = (String) ( theDecryptedString + charAtI[i]);
}
System.out.println(theDecryptedString);
return theDecryptedString;
}
}