搜索
查看: 783|回复: 16
打印 上一主题 下一主题

[原创] 搞了半天做出来的……

[复制链接]
跳转到指定楼层
楼主
发表于 2014-9-3 21:52:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 4399APPLE 于 2014-9-5 12:15 编辑

JAVA制作
tes.rar (103.03 KB, 下载次数: 58)

Encry.rar

1.12 KB, 下载次数: 21

推荐
发表于 2014-9-6 10:56:35 | 只看该作者
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;

public class Encry implements ActionListener {
        static JFrame w = new JFrame();
        public static void main(String args[]) {
               
                JButton btnKey = new JButton("生成密钥");
                JButton btnEnc = new JButton("文件加密");
                JButton btnDec = new JButton("文件解密");
               
                Encry e = new Encry();
                btnKey.addActionListener(e);
                btnEnc.addActionListener(e);
                btnDec.addActionListener(e);
               
                w.setSize(150, 140);
                w.add(btnKey);
                w.add(btnEnc);
                w.add(btnDec);
                w.setLayout(new FlowLayout());
                w.setResizable(false);
                w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                w.setVisible(true);
        }
       
        @Override
        public void actionPerformed(ActionEvent arg0) {
                String s;
                if(arg0.getActionCommand() == "生成密钥") {
                        try {
                                File f = new File("C:/key.key");
                               
                                FileOutputStream fos = new FileOutputStream(f);
                               
                                for(int i = 0;i < 128; i++)
                                        fos.write((int)(Math.random()*128));
                               
                                fos.close();
                               
                                JOptionPane.showMessageDialog(null, "生成密钥成功", "成功", JOptionPane.INFORMATION_MESSAGE);
                        }catch (Exception ee) {
                                JOptionPane.showMessageDialog(null, "生成密钥失败", "失败", JOptionPane.ERROR_MESSAGE);
                                ee.printStackTrace();
                        }
                       
                }
                if(arg0.getActionCommand() == "文件加密") {
                        w.setVisible(false);
                        s = JOptionPane.showInputDialog(null, "请输入文件路径(注意, 此处使用/代表\\):");
                        if(JOptionPane.showOptionDialog(null, "确定要加密码?加密后生成的文件将覆盖原来的文件!", "确定?", 2, 2, null, null, null) == 0) {
                                try {
                                        int key[] = new int[128];
                                        File keyFile = new File("C:/key.key");
                                        File inFile = new File(s);
                                        File outFile = new File(s + "test");
                                       
                                        FileInputStream keyFis = new FileInputStream(keyFile);
                                       
                                        for(int i = 0;i < 128;i ++)
                                                key[i] = keyFis.read();
                                       
                                        keyFis.close();
                                       
                                        FileInputStream fis = new FileInputStream(inFile);
                                        FileOutputStream fos = new FileOutputStream(outFile);
                                       
                                        int length = fis.available();
                                        for(int i = 0;i < length;i ++)
                                                fos.write(fis.read() + key[i%128]);
                                       
                                        fis.close();
                                        fos.close();
                                       
                                        FileInputStream fis2 = new FileInputStream(outFile);
                                        FileOutputStream fos2 = new FileOutputStream(inFile);
                                       
                                        int length2 = fis2.available();
                                        for(int i = 0;i < length2;i ++)
                                                fos2.write(fis2.read());
                                       
                                        fis2.close();
                                        fos2.close();
                                       
                                        outFile.delete();
                                        JOptionPane.showMessageDialog(null, "加密文件成功", "成功", JOptionPane.INFORMATION_MESSAGE);
                                }catch (Exception ee) {
                                        JOptionPane.showMessageDialog(null, "加密文件失败", "失败", JOptionPane.ERROR_MESSAGE);
                                        ee.printStackTrace();
                                }
                                w.setVisible(true);
                        }
                }
                if(arg0.getActionCommand() == "文件解密") {
                        w.setVisible(false);
                        s = JOptionPane.showInputDialog(null, "请输入文件路径(注意, 此处使用/代表\\):");
                        if(JOptionPane.showOptionDialog(null, "确定要解密码?解密后生成的文件将覆盖原来的文件!", "确定?", 2, 2, null, null, null) == 0) {
                                try {
                                        int key[] = new int[128];
                                        File keyFile = new File("C:/key.key");
                                        File inFile = new File(s);
                                        File outFile = new File(s + "test");
                                       
                                        FileInputStream keyFis = new FileInputStream(keyFile);
                                       
                                        for(int i = 0;i < 128;i ++)
                                                key[i] = keyFis.read();
                                       
                                        keyFis.close();
                                       
                                        FileInputStream fis = new FileInputStream(inFile);
                                        FileOutputStream fos = new FileOutputStream(outFile);
                                       
                                        int length = fis.available();
                                        for(int i = 0;i < length;i ++)
                                                fos.write(fis.read() - key[i%128]);
                                       
                                        fis.close();
                                        fos.close();
                                       
                                        FileInputStream fis2 = new FileInputStream(outFile);
                                        FileOutputStream fos2 = new FileOutputStream(inFile);
                                       
                                        int length2 = fis2.available();
                                        for(int i = 0;i < length2;i ++)
                                                fos2.write(fis2.read());
                                       
                                        fis2.close();
                                        fos2.close();
                                       
                                        outFile.delete();
                                        JOptionPane.showMessageDialog(null, "解密文件成功", "成功", JOptionPane.INFORMATION_MESSAGE);
                                }catch (Exception ee) {
                                        JOptionPane.showMessageDialog(null, "解密文件失败", "失败", JOptionPane.ERROR_MESSAGE);
                                        ee.printStackTrace();
                                }
                                w.setVisible(true);
                        }
                }
        }
}
沙发
 楼主| 发表于 2014-9-4 18:24:12 | 只看该作者
源码等一下发
板凳
 楼主| 发表于 2014-9-4 18:24:18 | 只看该作者
我忘记发了
地板
 楼主| 发表于 2014-9-5 12:15:56 | 只看该作者
下面的是源代码
5#
发表于 2014-9-6 10:56:32 | 只看该作者
破译成功
7#
发表于 2014-9-6 10:57:10 | 只看该作者
放c盘里不怕系统运行缓慢
8#
 楼主| 发表于 2014-9-8 15:58:15 | 只看该作者
Cminister 发表于 2014-9-6 10:57
放c盘里不怕系统运行缓慢

呵呵                        
9#
发表于 2014-9-8 23:14:33 | 只看该作者

呵呵是十大最讨厌用语之一啊= =

点评

谁说的??  发表于 2014-9-13 08:43
10#
发表于 2014-9-20 08:59:10 | 只看该作者
Cminister 发表于 2014-9-6 10:57
放c盘里不怕系统运行缓慢

谣言止于智者,聊天止于呵呵

点评

呵呵,呵呵。  发表于 2018-2-1 13:56
11#
发表于 2014-9-20 11:18:04 | 只看该作者
cad20020601 发表于 2014-9-20 08:59
谣言止于智者,聊天止于呵呵

我一直被Copy,但从未被surpass
12#
发表于 2014-9-21 10:23:55 | 只看该作者
没有java运行环境,没法运行
13#
发表于 2015-6-19 22:01:44 | 只看该作者
话说我只用JavaScript写我的世界js
14#
发表于 2016-7-24 16:54:54 | 只看该作者
Cminister 发表于 2014-9-6 10:56
import java.awt.*;
import javax.swing.*;
import java.io.*;

运行不成功
15#
发表于 2016-8-9 23:12:07 | 只看该作者
我打个酱油就走
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表