VS文件异或加解密

VS文件异或加解密

注意:异或加解密方式是一样

参数一 需要加密的文件
参数二 加密后的文件
参数三 加密字符串

#include <iostream>
#include <fstream>
#include <string.h> 
using namespace std;

int fileXOR(char *in_fname,char *out_fname,char *pwd)
{
	FILE *in_file,*out_file;
	in_file=fopen(in_fname,"rb");//以读的方式打开二进制文件
	if(in_file==NULL)//如果打开失败
	{ 
		cout<<"Open file error"; 
	} 
	out_file=fopen(out_fname,"wb");//以写的方式打开二进制文件
	if(out_file==NULL)//如果创建失败
	{
		cout<<"Create file error";
	}

	_fseeki64(in_file,0,SEEK_SET);
    _fseeki64(in_file,0,SEEK_END);// 为了知道文件的大小 
    long long BK_SIZE=_ftelli64(in_file);//ftell()的返回值为文件的大小 
    _fseeki64(in_file,0,SEEK_SET);
	printf("%d",BK_SIZE);
	
	char *readbuf=NULL;
    readbuf=(char *)malloc(BK_SIZE);
    if(readbuf==NULL)
    {
        return 0;
    }
    memset(readbuf,'\0',BK_SIZE);

	char *readbuf1=NULL;
    readbuf1=(char *)malloc(BK_SIZE);
    if(readbuf1==NULL)
    {
        return 0;
    }
    memset(readbuf1,'\0',BK_SIZE);
	
	int ret=fread(readbuf,1,BK_SIZE,in_file);
	int jj=0,j=0;
	
	while(pwd[++jj]);
	for(int i = 0;i<BK_SIZE;i++)
	{
		readbuf1[i]=readbuf[i]^pwd[j>=jj?j=0:j++];
	}
	fwrite(readbuf1,BK_SIZE,1,out_file);
	
	fclose(in_file);
	fclose(out_file);
}

int main()
{
	fileXOR("./1.jpg","./2.jpg","1433223");
	system("pause");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值