summaryrefslogtreecommitdiff
path: root/src/xor.c
blob: 15411ab8548d535975222defce515443ea697af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <err.h>

int
main(int argc, char *argv[])
{
   if (argc < 2)
      errx(EXIT_FAILURE"usage: %s hex ... < input > output", argv[0]);

   uint8_t buf[4096];
   for (size_t ret, c = 0; (ret = fread(buf, 1sizeof(buf), stdin)) > 0;) {
      for (size_t i = 0; i < ret; ++i, c = (c + 1) % (argc - 1))
          buf[i] ^= strtoull(argv[c + 1], 016);
      fwrite(buf, 1, ret, stdout);
   }

   return EXIT_SUCCESS;
}