diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2019-03-17 15:30:43 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2019-03-25 09:33:18 +0200 |
commit | 662d78b9a5bebdb98dc178ebd1f8e3384793c104 (patch) | |
tree | ea02633b41bd08957d3490d40553d389b1e78a36 /src/xor.c |
Diffstat (limited to 'src/xor.c')
-rw-r--r-- | src/xor.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/xor.c b/src/xor.c new file mode 100644 index 0000000..15411ab --- /dev/null +++ b/src/xor.c @@ -0,0 +1,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, 1, sizeof(buf), stdin)) > 0;) { + for (size_t i = 0; i < ret; ++i, c = (c + 1) % (argc - 1)) + buf[i] ^= strtoull(argv[c + 1], 0, 16); + fwrite(buf, 1, ret, stdout); + } + + return EXIT_SUCCESS; +} |