文件加密之异或加密(C++实现)
来源:互联网 发布:黑暗网络进入方法 编辑:程序博客网 时间:2024/05/16 10:05
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
//加密函数
void Encryption(char *in_fname,char *out_fname,char *pwd)
{
FILE *in_file,*out_file;
register char ch;
int x;
x=strlen(pwd);
in_file=fopen(in_fname,"rb");//以读的方式打开二进制文件
if(in_file==NULL)//如果打开失败
{
cout<<"Open file error";
exit(1);
}
out_file=fopen(out_fname,"wb");//以写的方式打开二进制文件
if(out_file==NULL)//如果创建失败
{
cout<<"Create file error";
exit(1);
}
//一下两断注释代码,要选其一进行使用
/*
这一断注释代码的功能是只对文件的前几位加密,可以提高读写速度,主要用于视频、音频文件,因为只要这类文件的前几位一经修改,是无法正常播放的。
ch=fgetc(in_file);
for(int i=0;i<=x;i++)
{
fputc(ch^pwd[i],out_file); //fputc函数是向文件写入一位字符
ch=fgetc(in_file); //fgetc()函数是得到文件的一个字符,会自动使指针后移一位
}
while(!feof(in_file))
{
fputc(ch,out_file);
ch=fgetc(in_file);
}
*/
/*
这一断注释代码的功能是对文件的所有位加密,主要用于文本文件。
while(!feof(in_file))
{
fputc(ch^pwd[i>=x?i=0:i++],out_file);
ch=fgetc(in_file);
}
*/
fclose(in_file);
fclose(out_file);
}
void main()
{
char in_fname[30],out_fname[30],pwd[30];
cout<<"Please input file name which you want to be encrypted:"<<endl;//输入想要加密文件的文件名
cin>>in_fname;
cout<<"Please input file name which which will be output:"<<endl;//输出加密后文件的文件名
cin>>out_fname;
cout<<"Please input password:"<<endl;//输入密码
cin>>pwd;
Encryption(in_fname,out_fname,pwd);//调用加密函数
cout<<"Success!"<<endl;
}
#include <fstream>
#include <string.h>
using namespace std;
//加密函数
void Encryption(char *in_fname,char *out_fname,char *pwd)
{
FILE *in_file,*out_file;
register char ch;
int x;
x=strlen(pwd);
in_file=fopen(in_fname,"rb");//以读的方式打开二进制文件
if(in_file==NULL)//如果打开失败
{
cout<<"Open file error";
exit(1);
}
out_file=fopen(out_fname,"wb");//以写的方式打开二进制文件
if(out_file==NULL)//如果创建失败
{
cout<<"Create file error";
exit(1);
}
//一下两断注释代码,要选其一进行使用
/*
这一断注释代码的功能是只对文件的前几位加密,可以提高读写速度,主要用于视频、音频文件,因为只要这类文件的前几位一经修改,是无法正常播放的。
ch=fgetc(in_file);
for(int i=0;i<=x;i++)
{
fputc(ch^pwd[i],out_file); //fputc函数是向文件写入一位字符
ch=fgetc(in_file); //fgetc()函数是得到文件的一个字符,会自动使指针后移一位
}
while(!feof(in_file))
{
fputc(ch,out_file);
ch=fgetc(in_file);
}
*/
/*
这一断注释代码的功能是对文件的所有位加密,主要用于文本文件。
while(!feof(in_file))
{
fputc(ch^pwd[i>=x?i=0:i++],out_file);
ch=fgetc(in_file);
}
*/
fclose(in_file);
fclose(out_file);
}
void main()
{
char in_fname[30],out_fname[30],pwd[30];
cout<<"Please input file name which you want to be encrypted:"<<endl;//输入想要加密文件的文件名
cin>>in_fname;
cout<<"Please input file name which which will be output:"<<endl;//输出加密后文件的文件名
cin>>out_fname;
cout<<"Please input password:"<<endl;//输入密码
cin>>pwd;
Encryption(in_fname,out_fname,pwd);//调用加密函数
cout<<"Success!"<<endl;
}
0 0
- 文件加密之异或加密(C++实现)
- C++:文件加密(凯撒加密、栅栏加密、异或加密四方加密、Base64加密)
- 文件加密(二) 异或加密
- XOR (异或)加密简单实现
- C语言 异或加密
- 简单异或加密实现
- C 使用异或(xor)加密/解密文件
- C 使用异或(xor)加密/解密文件
- c语言之文件加密
- 一个异或加密方案--C语言实现
- C语言:用异或^实现数据加密
- 加密文件或文件夹
- java实现简单的异或操作(用于文件简单加密)
- 简单异或加密(C语言)
- php 使用异或(XOR)加密/解密文件
- php 使用异或(XOR)加密/解密文件
- iOS开发资源文件进行XOR加密(异或加密)
- VB利用异或运算加密文件
- 点击其它地方关闭DIV
- 尺取法(滑窗法)的应用(POJ 3061,POJ 3320)
- apk反编译
- 以太网PHY 芯片之 MII/MDIO接口详解
- Virtual Box安装linux mint
- 文件加密之异或加密(C++实现)
- 数字倒序输出
- iOS开发UI-Quartz2D what about Quartz2D ?and how to use it ?
- linux下编译使用ffmpeg
- 全局认识运筹学
- A and B and Team Training——求最大组队数
- 99乘法表
- 嵌入式内核制作
- 黑马程序员---类的深入了解