www.pudn.com > c.rar > SAFE.C, change:1997-01-25,size:1539b


#include "stdio.h" 
#include "stdlib.h" 
#include "string.h" 
#include "io.h" 
#define MAXPATH 80 
void encrypt(int loopnum); 
FILE *secret; 
int i,handle,numtoget,loopnum; 
long size,filepos,numread; 
char filestr[MAXPATH],password[128]; 
unsigned char *buffer; 
main(int argc,char *argv[]) 
{ 
printf("\nV1-Valult it\n"); 
buffer=(unsigned char *)calloc(32767,1); 
if(buffer==NULL) 
{ 
printf("\nNot enough memory to run application.Please remove"); 
printf("\nall memory resident software and try again.\n"); 
exit(1); 
} 
if(argc>2) 
{ 
strcpy(filestr, argv[1]); 
for(i=2;i<=(argc-1);i++) 
strcat(password,argv[i]); 
} 
else 
{ 
printf("\nUsage:C:\>vault filename.ext password\n"); 
exit(2); 
} 
secret=fopen(filestr,"r+"); 
if(secret==NULL) 
{ 
printf("\nThe file was not found. Please check the spelling.\n"); 
exit(3); 
} 
handle=fileno(secret); 
size=filelength(handle); 
if(size<=32767) 
numtoget=size; 
else 
numtoget=32767; 
numread=0; 
do{ 
filepos=ftell(secret); 
fseek(secret,numread,0); 
_read(handle,buffer,numtoget); 
numread+=numtoget; 
encrypt(numtoget); 
fseek(secret,filepos,0); 
_write(handle,buffer,numtoget); 
if((numread+numtoget)>size) 
numtoget=size-numread; 
}while (numtoget!=0); 
fclose(secret); 
return(0); 
} 
/*********************************************************/ 
void encrypt(int loopnum) 
{ 
int passwordx,j; 
j=0; 
passwordx=7; 
do{ 
buffer[j]=buffer[j]^((255-(j&254))|(127^j)); 
passwordx++; 
if(passwordx>37) 
passwordx=7; 
buffer[j]=buffer[j]^password[passwordx]; 
j++; 
}while(j!=loopnum); 
}