-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.java
67 lines (56 loc) · 1.83 KB
/
Controller.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class Controller {
private View view;
private EncryptionEngine encryptionEngine;
public Controller(){
this.view=new View(this);
encryptionEngine=new EncryptionEngine(this);
}
public void encryptButtonClicked(){
try {
String key= view.getEncryptionKey();
char[] keyCha=key.toCharArray();
for(int i=0;i<key.length();i+=1){
if(!Character.isDigit(keyCha[i])){
throw new Exception("Not a numerical key!");
}
}
String inputText=view.getInputText();
char[] cha=inputText.toCharArray();
for(int i=0;i<cha.length;i+=1){
if(!Character.isUpperCase(cha[i])){
throw new Exception("Not a uppercase word!");
}
}
encryptionEngine.setEncryptionKey(Integer.parseInt(key));
String outputText = encryptionEngine.encrypt(inputText);
view.setOutputText(outputText);
} catch (Exception e) {
String errMsg=e.getMessage();
view.setOutputText(errMsg);
}
}
public void decryptButtonClicked(){
try {
String key= view.getEncryptionKey();
char[] keyCha=key.toCharArray();
for(int i=0;i<key.length();i+=1){
if(!Character.isDigit(keyCha[i])){
throw new Exception("Not a numerical key!");
}
}
String inputText=view.getInputText();
char[] cha=inputText.toCharArray();
for(int i=0;i<cha.length;i+=1){
if(!Character.isUpperCase(cha[i])){
throw new Exception("Not a uppercase word!");
}
}
encryptionEngine.setEncryptionKey(Integer.parseInt(key));
String outputText = encryptionEngine.decrypt(inputText);
view.setOutputText(outputText);
} catch (Exception e) {
String errMsg=e.getMessage();
view.setOutputText(errMsg);
}
}
}