黑马程序员技术交流社区
标题:
基础班学习之----文件加密小程序
[打印本页]
作者:
erer369852
时间:
2016-5-21 22:50
标题:
基础班学习之----文件加密小程序
package com.heima.test;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test1 {
public static void main(String[] args) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("copy.jpg"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy2.jpg"));
int b;
while((b = bis.read()) != -1) {
bos.write(b ^ 123); //一个数异或另一个数2次,值不变.
}
bis.close();
bos.close();
}
}
个人觉得这个小程序很有用,只要是文件形式,例如安装包,文本文件等都可以加密,
用到的原理很简单: 一个数异或另一个数2次,值不变
上面程序中,文件的每个字节异或上一个数,这个数就是密钥,解密的时候再次异或就可以了.
作者:
erer369852
时间:
2016-5-23 01:12
zhoujunjie 发表于 2016-5-23 01:08
66666666666666666666666666
public Demo1_66666() {
public static void main (Strnig[] args) {
while(true){
System.out.println("你好6,666")
}
}
}
作者:
娶个英文名字
时间:
2016-5-23 01:14
你说既然留不住你
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2