//*************************************//
//******** created by mamo139 *********//
//*** http://mamo139.altervista.org ***//
//*************************************//
#include <stdio.h>
#include <string.h>
int main () {
char key[20]="chiave";
FILE * pFile;
pFile = fopen ( "input.txt" , "rb" );
long lSize,b,x,keyl=strlen(key);
printf("keyl: %d key: %s\n",keyl,key);
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
fclose (pFile);
pFile = fopen ( "input.txt" , "rb" );
char *buf;
buf = (char *) malloc(lSize * sizeof(char));
b=fread( buf, 1, lSize, pFile);
fclose (pFile);
FILE * f_out;
f_out = fopen ( "output.txt" , "wb" );
for(x=0;x<b;x++){
buf[x] = buf[x] + key[x%(keyl)];
}
fwrite( buf, 1, b, f_out);
fclose (f_out);
return 0;
}