Encrypting a file in win API
Posted
by Kristian
on Stack Overflow
See other posts from Stack Overflow
or by Kristian
Published on 2010-06-01T16:08:57Z
Indexed on
2010/06/01
16:13 UTC
Read the original article
Hit count: 187
hi I have to write a windows api code that encrypts a file by adding three to each character.
so I wrote this now its not doing anything ... where i go wronge
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE filein,fileout;
filein=CreateFile
(L"d:\\test.txt",GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
fileout=CreateFile
(L"d:\\test.txt",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD really; //later this will be used to store how many bytes I succeed to read
do
{
BYTE x[1024]; //the buffer the thing Im using to read in
ReadFile(filein,x,1024,&really,NULL);
for(int i=0 ; i<really ; i++)
{
x[i]= (x[i]+3) % 256;
}
DWORD really2;
WriteFile(fileout,x,really,&really2,NULL);
}while(really==1024);
CloseHandle(filein);
CloseHandle(fileout);
return 0;
}
and if Im right how can i know its ok
© Stack Overflow or respective owner