Christophe HENRY
3d71aa2e6f
It's not designed to be used for cryptographic stuff, unless you know what you're doing or you want to hide from your little sister. Xit processes files in the memory and is not designed to treat huge data.
33 lines
786 B
C
33 lines
786 B
C
#include <stdio.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: xor [FILE]...\nAll files XORed to stdout, size: minimum of all.\n");
|
|
return(1);
|
|
}
|
|
int nbFiles = argc-1;
|
|
FILE *files[nbFiles];
|
|
bool errors = false;
|
|
for (int i=0;i<nbFiles;i++) {
|
|
files[i] = fopen(argv[i+1], "r");
|
|
if (files[i] == NULL) {
|
|
fprintf(stderr, "Could not open '%s'.\n", argv[i+1]);
|
|
errors = true;
|
|
}
|
|
}
|
|
if (errors) return(1);
|
|
char c[argc-1];
|
|
do {
|
|
int cc;
|
|
for (int i=0;i<nbFiles;i++) {
|
|
cc = fgetc(files[i]);
|
|
if (cc == EOF) break;
|
|
c[i] = (char)cc;
|
|
}
|
|
if (cc == EOF) break;
|
|
char xored = '\0';
|
|
for (int i=0;i<nbFiles;i++) xored ^= c[i];
|
|
printf("%c", xored);
|
|
} while(1);
|
|
}
|