import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.DES.converter._16TransfromTo2;
import com.DES.converter._2TransfromTo16;
import com.DES.operation.Decrypt;
import com.DES.operation.Encrypt;
import com.DES.operation.Operate;
public class MyFrame extends JFrame {
public MyFrame() {
// TODO Auto-generated constructor stub
luanch();
}
public static void main(String[] args) {
new MyFrame().luanch();
}
JTextField mingwenfield = new JTextField(46);
JTextField keyfield = new JTextField(46);
JTextField result = new JTextField(46);
// JTextArea area = new JTextArea(6,46);
JLabel content_label = new JLabel("请输入16位十六进制明文:");
JLabel key_label = new JLabel("请输入16位十六进制密钥:");
JLabel result_label = new JLabel(" 输出结果为:");
JLabel process_label = new JLabel(" 过程:");
JButton button = new JButton("加密");
JButton button2 = new JButton("解密");
JTextArea textArea = new JTextArea();
JScrollPane scroll = new JScrollPane(textArea);
JLabel keduchi1 = new JLabel("0123456789ABCDEF");
JLabel keduchi2 = new JLabel("0123456789ABCDEF");
JPanel panel = new JPanel(null);
public void luanch() {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Decrypt test = new Decrypt();
String mingwen = new _16TransfromTo2(mingwenfield.getText())
.transform();
String key = new _16TransfromTo2(keyfield.getText())
.transform();
if (mingwen.length() == 64 && key.length() == 64) {
for (int i = 0; i < mingwen.length(); i++) {
char word = mingwen.charAt(i);
if (word != '0' && word != '1') {
result.setText("明文请输入16进制数");
result_label
.setText(" 错误:");
return;
}
}
for (int i = 0; i < key.length(); i++) {
char word = key.charAt(i);
if (word != '0' && word != '1') {
result.setText("密码请输入16进制数");
result_label
.setText(" 错误:");
return;
}
}
test.setPlaintext(mingwen);
test.setKey(key);
test.luanch();
result.setText(new _2TransfromTo16(test.finalresult)
.transform());
result_label.setText(" 输出结果为:");
textArea.setText(test.groundresult);
test.groundresult = "";
} else {
result.setText("请输入16个16进制数");
result_label
.setText(" 错误:");
textArea.setText("");
}
}
});
button2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Encrypt test = new Encrypt();
String miyao = new _16TransfromTo2(keyfield.getText()).transform();
String miwen = new _16TransfromTo2(result.getText()).transform();
if (miwen.length() == 64 && miyao.length() == 64) {
for (int i = 0; i < miwen.length(); i++) {
char word = miwen.charAt(i);
if (word != '0' && word != '1') {
result.setText("明文请输入16进制数");
result_label
.setText(" 错误:");
return;
}
}
for (int i = 0; i < miyao.length(); i++) {
char word = miyao.charAt(i);
if (word != '0' && word != '1') {
result.setText("密码请输入16进制数");
result_label
.setText(" 错误:");
return;
}
}
System.out.println("密文"+miwen);
System.out.println("密钥"+miyao);
test.setPlaintext(miwen);
test.setKey(miyao);
test.luanch();
mingwenfield.setText(new _2TransfromTo16(test.finalresult)
.transform());
result_label.setText(" 输出结果为:");
textArea.setText(test.groundresult);
test.groundresult = "";
} else {
result.setText("请输入16个16进制数");
result_label
.setText(" 错误:");
textArea.setText("");
}
}
}
);
textArea.setLineWrap(true);
content_label.setBounds(30, 20, 200, 30);
mingwenfield.setBounds(180, 20, 500, 30);
key_label.setBounds(30, 70, 200, 30);
keyfield.setBounds(180, 70, 500, 30);
result_label.setBounds(30, 120, 200, 30);
result.setBounds(180, 120, 500, 30);
process_label.setBounds(30, 300, 200, 30);
button.setBounds(700, 200, 70, 30);
button2.setBounds(700, 250, 70, 30);
keduchi1.setBounds(180, 0, 200, 30);
keduchi2.setBounds(180, 50, 200, 30);
this.setTitle("DES加密");
scroll.setBounds(180, 160, 500, 400);
panel.add(keduchi1);
panel.add(keduchi2);
panel.add(content_label);
panel.add(mingwenfield);
panel.add(key_label);
panel.add(keyfield);
panel.add(result_label);
panel.add(result);
panel.add(process_label);
panel.add(button2);
panel.add(scroll);
panel.add(button);
this.add(panel);
this.setBounds(300, 50, 800, 700);
this.setVisible(true);
}
}
- 1
- 2
- 3
前往页