Xortext.c

From Hackepedia
Jump to: navigation, search
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>


int
main(int argc, char *argv[])
{
 u_long count = 0;
 int keylen;
 char *key;
 u_char c;

 if (argc != 2) {
  fprintf(stderr, "must provide a key\n");
  exit(1);
 }

 key = argv[1];
 keylen = strlen(key);

 while (read(STDIN_FILENO, &c, sizeof(c)) > 0) {
  c ^= key[count % keylen];
  write(STDOUT_FILENO, &c, 1);
  count++;
 }

 return 0;
}