一个简单的加密解密方法实例
2013-05-23 11:34
726 查看
private int num =1;
/**
* 加密的原理就是读取原来数据的字节数
* 在原来字节数的基础上增加字节
* @param sourcefile原文件路径
* @param destfile新文件路径
* @throws IOException
*/
public void encode(String sourcefile, String destfile) throws IOException // 编码
{
FileReader in = new FileReader(sourcefile);
FileWriter out = new FileWriter(destfile);
int c;
while ((c = in.read()) != -1)
out.write((char)c+num);
in.close();
out.close();
}
/**
* 解密的原理就是读取被加密的数据的字节数
* 在原来字节数的基础上减少加密时相同的字节数
* @param sourcefile原文件路径
* @param destfile新文件路径
* @throws IOException
*/
public void decode(String sourcefile, String destfile) throws IOException // 解码
{
FileReader in = new FileReader(sourcefile);
FileWriter out = new FileWriter(destfile);
int c;
while ((c = in.read()) != -1)
out.write((char)c-num);
in.close();
out.close();
}
public static void main(String args[]) throws IOException {
EncryptText text = new EncryptText();
//text.encode("D://1.txt", "D://2.txt");
text.decode("D://2.txt", "D://3.txt");
}
/**
* 加密的原理就是读取原来数据的字节数
* 在原来字节数的基础上增加字节
* @param sourcefile原文件路径
* @param destfile新文件路径
* @throws IOException
*/
public void encode(String sourcefile, String destfile) throws IOException // 编码
{
FileReader in = new FileReader(sourcefile);
FileWriter out = new FileWriter(destfile);
int c;
while ((c = in.read()) != -1)
out.write((char)c+num);
in.close();
out.close();
}
/**
* 解密的原理就是读取被加密的数据的字节数
* 在原来字节数的基础上减少加密时相同的字节数
* @param sourcefile原文件路径
* @param destfile新文件路径
* @throws IOException
*/
public void decode(String sourcefile, String destfile) throws IOException // 解码
{
FileReader in = new FileReader(sourcefile);
FileWriter out = new FileWriter(destfile);
int c;
while ((c = in.read()) != -1)
out.write((char)c-num);
in.close();
out.close();
}
public static void main(String args[]) throws IOException {
EncryptText text = new EncryptText();
//text.encode("D://1.txt", "D://2.txt");
text.decode("D://2.txt", "D://3.txt");
}
相关文章推荐
- Java实现一个简单的加密解密方法
- 一个简单的加密解密方法(java、shell脚本)
- 异或加密法 在对文本进行简单加密的时候,可以选择用一个n位的二进制数,对原文进行异或运算。 解密的方法就是再执行一次同样的操作。
- 一个简单的加密,解密方法
- 异或加密法 在对文本进行简单加密的时候,可以选择用一个n位的二进制数,对原文进行异或运算。 解密的方法就是再执行一次同样的操作。
- 对一个件加密和解密的一个简单方法
- 又一个php加密和解密的方法
- 一个简单不过却很非常实用的PHP加密字符串方法
- 一个很实用的加密解密方法
- Java使用异或运算实现简单的加密解密算法实例代码
- C++ 简单的文件加密和解密 实例
- 一个最简单的加密解密算法(人人能懂)
- C++ 简单的文件加密和解密 实例
- 简单PHP对称加密解密方法、具有时效性的php加密解密函数
- Powershell实现加密解密文本文件方法实例
- 简单的加密解密方法
- 一个简单的c#加密,签名,验签,解密算法.(1)
- 一个简单的加密和解密程序——凯撒密码