C++ファイル暗号化方式1

1324 ワード

// ConsoleApplication3.cpp :              。
//

#include "stdafx.h"

#include 
#include  
#include "fstream"

using namespace std;

#define OK 0;
#define ERR -1;
#define KEY 0xa9;

int FileConvert(char *szOldFile,char *szNewFilew){

	if (!szOldFile || !szNewFilew){
		cout << "  ..." << endl; //out:14567  
		return ERR;
	}

	FILE * pOldFile = NULL;
	FILE * pNewFile = NULL;;
	char cTcmp;

	pOldFile = fopen(szOldFile,"rb");
	if (!pOldFile){
		cout << "    ..." << endl; //out:14567  
		return ERR;
	}

	pNewFile = fopen(szNewFilew, "wb");
	if (!pNewFile){
		cout << "    ..." << endl; //out:14567  
		return ERR;
	}

	cTcmp = fgetc(pOldFile) ^ KEY;
	while (!feof(pOldFile))
	{
		fputc(cTcmp, pNewFile);
		cTcmp = fgetc(pOldFile) ^ KEY;
	}

	fclose(pOldFile);
	fclose(pNewFile);

	return OK;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char *szOldFile = "E://BaiduNetdiskDownload//Jason2.jpg";
	char *szNewFilew = "E://BaiduNetdiskDownload//Jason3.jpg";

	char *szNewFilew0 = "E://BaiduNetdiskDownload//Jason4.jpg";
	FileConvert(szNewFilew, szNewFilew0);
	
	//cout << this << endl; //out:14567  
	system("pause");
	return 0;

}