XOR Arguments
From KnowWiki
Takes a file and XOR's its content with a given value. Fast C implementation.
/* * This work is hereby released into the Public Domain. */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <sys/stat.h> #define XORBYTE (0x8dUL) #define XORINT (XORBYTE | (XORBYTE << 8) | (XORBYTE << 16) | (XORBYTE << 24)) #ifdef __LP64__ #define XORLONG ((XORINT) | ((XORINT) << 32)) #define LONG2 3 #else #define XORLONG XORINT #define LONG2 2 #endif #define BUFSIZE (2048 << 10) #ifdef WIN32 #define MODE (S_IRUSR | S_IWUSR) #else #define MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) #define O_BINARY 0 #endif int main(int argc, char *argv[]) { unsigned long *buf; int i, r, fin, fout; fin = open(argv[1], O_RDONLY | O_BINARY); fout = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, MODE); buf = malloc((BUFSIZE >> LONG2) * sizeof(long)); while ((r = read(fin, buf, BUFSIZE)) > 0) { for (i = 0; i < ((r + sizeof(long) - 1) >> LONG2); i++) buf[i] ^= XORLONG; write(fout, buf, r); } free(buf); close(fout); close(fin); return 0; }