2013-01-29 21:53:17 -07:00
|
|
|
/*
|
2020-12-22 09:15:56 -07:00
|
|
|
* xor filter -- 2020 Neale Pickett <neale@woozle.org>
|
2017-07-20 09:27:06 -06:00
|
|
|
*
|
|
|
|
* This file is in the public domain. I make no promises about the functionality
|
2013-01-29 21:53:17 -07:00
|
|
|
* of this program.
|
2012-02-10 11:29:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-12-22 09:15:56 -07:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
int radix = 10;
|
|
|
|
int arg;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, "a")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'x':
|
|
|
|
radix = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Usage: %s [-x] m1 [m2 ...]\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv[optind]) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
arg = optind;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int c = getchar();
|
|
|
|
unsigned char mask;
|
|
|
|
|
|
|
|
if (!argv[arg]) {
|
|
|
|
arg = optind;
|
|
|
|
}
|
|
|
|
mask = strtol(argv[arg++], NULL, radix);
|
|
|
|
|
|
|
|
if (EOF == c) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
c ^= mask;
|
|
|
|
putchar(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-02-10 11:29:56 -07:00
|
|
|
}
|