Wednesday, 23 January 2008

XOR Encryption


#include <stdio.h>
#include <stdlib.h>

FILE * input,
* key,
* output;

int main(void) {
input = fopen("in.txt", "r");
key = fopen("key.txt", "r");
output = fopen("out.txt", "w");

if(!input) { puts("input failure"); return EXIT_FAILURE; }
if(!key) { puts("key failure"); return EXIT_FAILURE; }
if(!output) { puts("output failure"); return EXIT_FAILURE; }

while(!feof(input))
{ if(feof(key)) rewind(key); fputc(fgetc(input) ^ fgetc(key), output); }

return EXIT_SUCCESS;
}

No comments: