啊哈磊_编程从这里起步

标题: 搞了半天做出来的…… [打印本页]

作者: 4399APPLE    时间: 2014-9-3 21:52
标题: 搞了半天做出来的……
本帖最后由 4399APPLE 于 2014-9-5 12:15 编辑

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

Encry.rar

1.12 KB, 下载次数: 21


作者: 4399APPLE    时间: 2014-9-4 18:24
源码等一下发
作者: 4399APPLE    时间: 2014-9-4 18:24
我忘记发了
作者: 4399APPLE    时间: 2014-9-5 12:15
下面的是源代码
作者: Cminister    时间: 2014-9-6 10:56
破译成功
作者: Cminister    时间: 2014-9-6 10:56
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);
                        }
                }
        }
}

作者: Cminister    时间: 2014-9-6 10:57
放c盘里不怕系统运行缓慢
作者: 4399APPLE    时间: 2014-9-8 15:58
Cminister 发表于 2014-9-6 10:57
放c盘里不怕系统运行缓慢

呵呵                        
作者: cad20020601    时间: 2014-9-8 23:14
4399APPLE 发表于 2014-9-8 15:58
呵呵

呵呵是十大最讨厌用语之一啊= =
作者: cad20020601    时间: 2014-9-20 08:59
Cminister 发表于 2014-9-6 10:57
放c盘里不怕系统运行缓慢

谣言止于智者,聊天止于呵呵
作者: Cminister    时间: 2014-9-20 11:18
cad20020601 发表于 2014-9-20 08:59
谣言止于智者,聊天止于呵呵

我一直被Copy,但从未被surpass
作者: tangjijia_2014    时间: 2014-9-21 10:23
没有java运行环境,没法运行

作者: 1935515130    时间: 2015-6-19 22:01
话说我只用JavaScript写我的世界js
作者: adc    时间: 2016-7-24 16:54
Cminister 发表于 2014-9-6 10:56
import java.awt.*;
import javax.swing.*;
import java.io.*;

运行不成功
作者: s141336    时间: 2016-8-9 23:12
我打个酱油就走




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2