forked from dirtbags/fluffy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxor.c
49 lines (39 loc) · 729 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
/*
* xor filter -- 2017 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 <string.h>
int
main(int argc, char *argv[])
{
int start = 1;
int base = 0;
int arg;
if (argv[start] && (0 == strcmp(argv[start], "-x"))) {
base = 16;
start += 1;
}
if (start + 1 > argc) {
fprintf(stderr, "Usage: %s [-x] m1 [m2 ...]\n", argv[0]);
return 1;
}
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;
}