forked from MasterFlomaster1/JFXCrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleJavaCrypter.java
More file actions
107 lines (89 loc) · 3.04 KB
/
Copy pathSimpleJavaCrypter.java
File metadata and controls
107 lines (89 loc) · 3.04 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
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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SimpleJavaCrypter extends JFrame{
private JButton btn1 = new JButton("Encrypt");
private JButton btn2 = new JButton("Decrypt");
private JLabel lbl1 = new JLabel("Enter your line here: ");
private JLabel lbl2 = new JLabel("Result: ");
private JTextField field = new JTextField();
private JTextField field2 = new JTextField();
public static void main(String[] args) {
new SimpleJavaCrypter();
}
public SimpleJavaCrypter(){
super("SimpleJavaCrypter");
this.setSize(410, 210);
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setLayout(null);
lbl1.setBounds(139, 10, 132, 20);
this.add(lbl1);
field.setBounds(50, 40, 310, 20);
this.add(field);
btn1.setBounds(50, 70, 150, 30);
btn1.addActionListener(new ActionListener1());
this.add(btn1);
btn2.setBounds(210, 70, 150, 30);
btn2.addActionListener(new ActionListener2());
this.add(btn2);
lbl2.setBounds(184, 110, 42, 20);
this.add(lbl2);
field2.setBounds(50, 140, 310, 20);
this.add(field2);
}
private String crypt(boolean encrypting, String line) {
String encrypted = "";
for (int i=0;i<line.length();i++) {
encrypted += cryptChar(encrypting, line.charAt(i));
}
return encrypted;
}
private char cryptChar(boolean encrypt, char c) {
String CHECKS = ("abcdefghijklmnopqrstuvwxyz1234567890");
String REPLACES = ("0qa9zxs3wedc6vf28r5tgb7nhyujm1kiolp4");
int index = 0;
if (encrypt) {
for (int i = 0; i < CHECKS.length(); i++) {
if (c == CHECKS.charAt(i)) {
index = i;
break;
} else {
index++;
}
}
return REPLACES.charAt(index);
} else {
for (int i = 0; i < REPLACES.length(); i++) {
if (c == REPLACES.charAt(i)) {
index = i;
break;
} else
index++;
}
return CHECKS.charAt(index);
}
}
public class ActionListener1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = field.getText();
field2.setText(result(true, text));
}
}
public class ActionListener2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = field.getText();
field2.setText(result(false, text));
}
}
private String result(boolean encrypt, String line){
String word;
if (encrypt){
word = crypt(true, line.toLowerCase());
} else {
word = crypt(false, line.toLowerCase());
}
return word;
}
}