So I gather you're experimenting with XOR encryption? (Sometimes it's easier -- and better -- to state the problem, and/or the "big picture", rather than perceived issues with assumed solutions.) Anyways, a number of your latest posts seems to point me toward that.
And it's been kinda slow, and I've never written one that I can remember, so I decided to play along at home. Here is something to compare with after you've finished or as you continue developing your code. I'm sure others will be along soon to nitpick it as well.
Doing something like this...
* argv - name of input file to encrypt/decrypt
* argv - name of output file
* argv - crypt key
int main(int argc, char *const *argv)
if ( argc == 4 )
FILE *input = fopen(argv, "rb");
FILE *output = fopen(argv, "wb");
if ( input != NULL && output != NULL )
unsigned char buffer[BUFSIZ];
size_t count, i, j = 0;
count = fread(buffer, sizeof *buffer, sizeof buffer, input);
for ( i = 0; i < count; ++i )
buffer[i] ^= argv[j++];
if ( argv[j] == '\0' )
j = 0; /* restart at the beginning of the key */
fwrite(buffer, sizeof *buffer, count, output);
} while ( count == sizeof buffer );
You should find that main.c matches file.txt.
H:\Forums>xorcrypt main.c file.bin key
H:\Forums>xorcrypt file.bin file.txt key