Xit is a Python program that applies XOR to files. 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. https://sbgodin.fr/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
786 B

#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");
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);