-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncryptionEngine.java
44 lines (26 loc) · 1010 Bytes
/
EncryptionEngine.java
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
38
39
40
41
42
43
44
public class EncryptionEngine {
public Controller controller;
public int encryptionKey;
public EncryptionEngine(Controller controller){
}
public void setEncryptionKey(int key){
this.encryptionKey=key;
}
public int getEncryptionKey(){
return encryptionKey;
}
public String encrypt(String inputText){
char[] inCharArr = inputText.toCharArray();
for (int i=0;i<inputText.length();i++){
inCharArr[i] = (char) (((((int)inCharArr[i] - 'A') +encryptionKey)% 26 )+ 'A');
}
return new String (inCharArr);
}
public String decrypt(String inputText){
char[] inCharArr = inputText.toCharArray();
for (int i=0;i<inputText.length();i++){
inCharArr[i] = (char) ((((((int)inCharArr[i] - 'A') -encryptionKey%26)+26 )% 26 )+ 'A');
}
return new String (inCharArr);
}
}