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[]) {
|
2021-02-02 19:11:32 -07:00
|
|
|
int radix = 0;
|
2020-12-22 09:15:56 -07:00
|
|
|
int arg;
|
|
|
|
int c;
|
|
|
|
|
2021-02-02 20:05:46 -07:00
|
|
|
while ((c = getopt(argc, argv, "x")) != -1) {
|
2020-12-22 09:15:56 -07:00
|
|
|
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
|
|
|
}
|