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

#define BUFSIZE 8192

int main(int argc, char **argv) {

    unsigned char buf[BUFSIZE], *p;
    int ret, bytecount=0, keylength;
    
    if (argc<2) { 
        printf("Usage: decrypt <key>\n");
        exit(EXIT_FAILURE);
    }
    
    keylength = strlen(argv[1]);
    
    while ((ret = read(0, buf, sizeof(buf))) > 0) 
        for (p = buf; ret > 0; ret--, p++) 
            printf("%c", (~*p - *((argv[1]+keylength) - bytecount % keylength)) ^ *(argv[1] + bytecount++ % keylength));

    return EXIT_SUCCESS;
}


