-
Notifications
You must be signed in to change notification settings - Fork 0
/
demotwo.java
136 lines (106 loc) · 3.42 KB
/
demotwo.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.geometry.*;
import javafx.event.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import java.io.*;
public class demotwo
{
Integer shift=new Integer(0);
GridPane gridPane = new GridPane();
public demotwo(Stage stage)
{
gridPane.setAlignment(Pos.CENTER);
TextField src = new TextField();
TextField des = new TextField();
TextField key = new TextField();
Label label=new Label();
src.setPromptText("--source--");
des.setPromptText("--destination--");
ComboBox<String> choice= new ComboBox<>();
choice .setValue("--select--");
choice.getItems().addAll("ceaserCipher","vigereneCipher","transPositionCipher");
Button srcBt = new Button("Browse");
Button desBt = new Button("Browse");
srcBt.setOnAction(event->{
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(stage);
if(selectedFile!=null)
{
src.setText(selectedFile.getAbsolutePath());
}
});
desBt.setOnAction(event->{
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showSaveDialog(stage);
if(selectedFile!=null)
{
des.setText(selectedFile.getAbsolutePath());
}
});
Button encrypt = new Button("Encrypt");
Button decrypt = new Button("Decrypt");
encrypt.setOnAction(e->{
String srcSt = src.getText();
String desSt = des.getText();
if(choice.getValue().toString().equals("ceaserCipher"))
{
int shift = Integer.parseInt(key.getText());
new caesarCipher().writeEncryptionToFile(srcSt, desSt, shift);
label.setText("CeaserCipher Encryption Process Completed");
gridPane.add(label,0,5);
}
if(choice.getValue().toString().equals("vigereneCipher"))
{
String keySt = key.getText();
new vigenereCipher().writeEncryptionToFile(srcSt, desSt, keySt);
label.setText("Vigerene Cipher Encryption Process Completed");
gridPane.add(label,0,5);
}
if(choice.getValue().toString().equals("transPositionCipher"))
{
String k2 = key.getText();
new transPosition().writeEncryptionToFile(srcSt, desSt, k2);
label.setText("Transposition Encryption Process Completed");
gridPane.add(label,0,5);
}
});
decrypt.setOnAction(e->{
String srcSt = src.getText();
String desSt = des.getText();
if(choice.getValue().toString().equals("ceaserCipher"))
{
int shift = Integer.parseInt(key.getText());
new caesarCipher().writeDecryptionToFile(srcSt, desSt, shift);
label.setText("Ceaser Cipher Decryption Process Completed");
gridPane.add(label,0,5);
}
if(choice.getValue().toString().equals("vigereneCipher"))
{
String keySt = key.getText();
new vigenereCipher().writeDecryptionToFile(srcSt, desSt, keySt);
label.setText(" Vigerene Cipher Decryption Process Completed");
gridPane.add(label,0,5);
}
if(choice.getValue().toString().equals("transPositionCipher"))
{
String k2 = key.getText();
label.setText("Process Can Not Be Completed");
gridPane.add(label,0,5);
}
});
gridPane.add(src,0,0);
gridPane.add(srcBt,1,0);
gridPane.add(des,0,1);
gridPane.add(desBt,1,1);
gridPane.add(choice,0,2);
gridPane.add(key,0,3);
gridPane.add(encrypt,0,4);
gridPane.add(decrypt,1,4);
}
}