-
Notifications
You must be signed in to change notification settings - Fork 10
/
xor.c
52 lines (42 loc) · 833 Bytes
/
xor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* xor filter -- 2020 Neale Pickett <[email protected]>
*
* This file is in the public domain. I make no promises about the functionality
* of this program.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
int radix = 0;
int arg;
int c;
while ((c = getopt(argc, argv, "x")) != -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;
}