Skip to content

Commit 2be501c

Browse files
authored
Everythingfor the Gui
Everything in the GUI is in the console.
1 parent 675c5e9 commit 2be501c

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

SafeFile GUI/CeaserSgui.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
import java.awt.GridLayout;
33
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
5+
import java.util.Arrays;
56

67
import javax.swing.*;
78

9+
10+
811
public class CeaserSgui extends JFrame{
912

10-
private JButton encryptC;
13+
private JButton encryptC, encryptA;
1114
private JLabel message1;
15+
private JCheckBox saveF;
1216
//Offset for the Ceaser Cypher and multby for how much to multiply for AlphaNum
1317
private JTextField offset, messageS;
1418

@@ -52,14 +56,75 @@ private void createView() {
5256
offset = new JTextField();
5357
panel.add(offset);
5458

55-
messageS.setText("Offset for Ceaser Cypher");
59+
messageS.setText("Number to Offset or Multiply");
5660
offset.setText("Message to Encrypt");
5761

5862
encryptC = new JButton("Encrypt With Ceaser Cypher");
5963
encryptC.addActionListener(
6064
new ButtonCounterActionListener()
6165
);
66+
6267
panel.add(encryptC);
68+
69+
saveF = new JCheckBox("Save File to txtE.txt ?");
70+
panel.add(saveF);
71+
72+
73+
//Adding in button to encrypt with AlphaNum
74+
encryptA = new JButton("Encrypt With AlphaNum");
75+
encryptA.addActionListener(new ActionListener() {
76+
public void actionPerformed(ActionEvent e) {
77+
78+
//eNCRYPTING cODE FOR aLPHAnUM
79+
80+
String message = offset.getText();
81+
int num = Integer.parseInt(messageS.getText());
82+
83+
String t = "";
84+
for (int i = 0; i < message.length(); ++i) {
85+
char ch = message.charAt(i);
86+
if (!t.isEmpty()) {
87+
t += " ";
88+
}
89+
int n = (int)ch - (int)'a' + 1;
90+
t += String.valueOf(n);
91+
}
92+
System.out.println(t);
93+
94+
// The string you want to be an integer array.
95+
String[] integerStrings = t.split(" ");
96+
// Splits each spaced integer into a String array.
97+
int[] integers = new int[integerStrings.length];
98+
// Creates the integer array.
99+
for (int i = 0; i < integers.length; i++){
100+
integers[i] = Integer.parseInt(integerStrings[i]);
101+
//Parses the integer for each string.
102+
}
103+
104+
105+
for (int i = 0; i < integers.length; i++)
106+
integers[i] = integers[i] * num;
107+
108+
109+
System.out.println("Encrypted Message: " + Arrays.toString(integers));
110+
message1.setText("Encrypted Message: " + Arrays.toString(integers));
111+
112+
Boolean sel = saveF.isSelected();
113+
114+
if (sel =true) {
115+
116+
createfile c = new createfile();
117+
c.openFile();
118+
c.addRecords( Arrays.toString(integers));
119+
c.closeFile();
120+
121+
}
122+
}
123+
124+
} );
125+
126+
panel.add(encryptA);
127+
63128
}
64129

65130

SafeFile GUI/createfile.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
import java.io.*;
4+
import java.lang.*;
5+
import java.util.*;
6+
7+
8+
public class createfile {
9+
10+
private Formatter x;
11+
12+
public void openFile() {
13+
try{
14+
x = new Formatter("textE.txt");
15+
} catch(Exception e) {
16+
System.out.println("Error with writting to file");
17+
}
18+
}
19+
public void addRecords(String en) {
20+
x.format("%s", en);
21+
22+
}
23+
24+
public void closeFile() {
25+
x.close();
26+
}
27+
28+
}
29+
30+

0 commit comments

Comments
 (0)