fluffy

Network Archaeology tools for Unix
git clone https://git.woozle.org/neale/fluffy.git

Neale Pickett  ·  2021-02-02

xor.c

 1/*
 2 * xor filter -- 2020 Neale Pickett <neale@woozle.org>
 3 *
 4 * This file is in the public domain.  I make no promises about the functionality
 5 * of this program. 
 6 */
 7
 8#include <stdio.h>
 9#include <stdlib.h>
10#include <unistd.h>
11
12int main(int argc, char* argv[]) {
13  int radix = 0;
14  int arg;
15  int c;
16
17  while ((c = getopt(argc, argv, "x")) != -1) {
18    switch (c) {
19      case 'x':
20        radix = 16;
21        break;
22      default:
23        fprintf(stderr, "Usage: %s [-x] m1 [m2 ...]\n", argv[0]);
24        return 1;
25    }
26  }
27
28  if (!argv[optind]) {
29    return 1;
30  }
31
32  arg = optind;
33
34  while (1) {
35    int c = getchar();
36    unsigned char mask;
37
38    if (!argv[arg]) {
39      arg = optind;
40    }
41    mask = strtol(argv[arg++], NULL, radix);
42
43    if (EOF == c) {
44      break;
45    }
46
47    c ^= mask;
48    putchar(c);
49  }
50
51  return 0;
52}