summaryrefslogtreecommitdiff
path: root/src/xor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xor.c')
-rw-r--r--src/xor.c20
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;
+}