#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
FILE *input, *output = stdout;
char *prog = argv[0];
char ch;
unsigned masklen, j;
unsigned long filelen, i;
int mask[]= {'t','e','s','t', '1',0,0,0, 0,'2',0,0, 0,0,'3',0,};
if(argc == 1 || argc == 2)
{
fprintf(stderr, "ERROR: %s requires a Source and Destination file.\n", prog);
exit(1);
}
else
{
if((input = fopen(*++argv, "rb")) == NULL)
{
fprintf(stderr, "ERROR: %s can not open file %s.\n", prog, *argv);
exit(1);
}
if((output = fopen(*++argv, "ab")) == NULL)
{
fprintf(stderr, "ERROR: %s can not create file %s.\n", prog, *argv);
exit(2);
}
}
fprintf(stdout, "Multi-Byte XOR Encoder/Decoder by typedeaF #
www.osix.net\n\n");
masklen = sizeof(mask)/sizeof(mask[0]);
fseek(input, 0L, SEEK_END);
filelen = ftell(input);
fseek(input, 0L, SEEK_SET);
fprintf(stdout, "Using mask: \"");
for(i = 0L; i < masklen; i++)
{
if(mask[i] == 0)
fprintf(stdout, "-");
else
fprintf(stdout, "%c", mask[i]);
}
fprintf(stdout, "\"\n");
for(i = 0L, j = 0; i < filelen; i++, j++)
{
ch = fgetc(input);
if(j == masklen)
j = 0;
if(mask[j] == 0)
fputc(ch, output);
else
fputc((mask[j]^ch)&0xFF, output);
}
fclose(input);
fclose(output);
return 0;
}
This is the real data in the plain text file. (plain text)
test1----2-----3-test1----2----3-test1----2-- (mask)
XXXXXis tXe reaX XXXXXin tXe plXiXXXXXt fiXe. (results (X is just symbolic here))