#include "stdafx.h"
#include <Windows.h>
#include <io.h>
#define BUF_SIZE 256
BOOL cci_f(LPCTSTR,LPCTSTR,DWORD);
int _tmain (int argc, LPTSTR argv [])
{
if(argc != 4)
{printf("cci shift file1 file2"); return 1;}
if(!cci_f(argv[2],argv[3],_wtoi(argv[1])))
{printf("false"); return 2;}
return 0;
}
BOOL cci_f(LPCTSTR fIn,LPCTSTR fOut,DWORD shift){
HANDLE hIn,hOut;
DWORD nIn,nOut,iCopy;
CHAR aBuffer[BUF_SIZE],ccBuffer[BUF_SIZE];
BOOL writeOK=TRUE;
hIn=CreateFile(fIn,GENERIC_READ,0,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if(hIn==INVALID_HANDLE_VALUE){
return FALSE;
}
hOut=CreateFile(fOut,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
if(hOut==INVALID_HANDLE_VALUE) return FALSE;
while(ReadFile(hIn,aBuffer,BUF_SIZE,&nIn,NULL)&&
nIn>0 && writeOK){
for(iCopy=0;iCopy<nIn;iCopy++)
ccBuffer[iCopy]=(aBuffer[iCopy]+shift) % 256;
//printf("%d",nIn);
writeOK=WriteFile(hOut,ccBuffer,nIn,&nOut,NULL);
}
CloseHandle(hIn);
CloseHandle(hOut);
return writeOK;
}
效果如下: