fluffy/xor.c

50 lines
729 B
C
Raw Normal View History

2013-01-29 21:53:17 -07:00
/*
* xor filter -- 2017 Neale Pickett <zephyr@dirtbags.net>
*
* 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>
#include <string.h>
int
main(int argc, char *argv[])
{
2013-01-29 21:53:17 -07:00
int start = 1;
int base = 0;
int arg;
if (argv[start] && (0 == strcmp(argv[start], "-x"))) {
2013-01-29 21:53:17 -07:00
base = 16;
start += 1;
}
if (start + 1 > argc) {
fprintf(stderr, "Usage: %s [-x] m1 [m2 ...]\n", argv[0]);
return 1;
}
2013-01-29 21:53:17 -07:00
arg = start;
while (1) {
int c = getchar();
unsigned char mask;
if (!argv[arg]) {
arg = start;
}
mask = strtol(argv[arg++], NULL, base);
if (EOF == c) {
break;
}
c ^= mask;
putchar(c);
}
return 0;
2012-02-10 11:29:56 -07:00
}