#include #include #include int main(int argc, char *argv[]) { //reads a message <4096B and XORs it with key argv[1] in file argv[2] //message ends with string "@@@" after a white character. //To retrieve the original message, use onetimebluh.c FILE * keyfile = fopen(argv[1],"r"); FILE * crypt = fopen(argv[2],"w"); char msg[4096]; printf("Write a message.\n It will be encrypted in file %s ",argv[2]); printf("with key %s\n",argv[1]); printf("When you're done, use the EOF sequence @@@. It must follow a white space!\n"); char c_aux; int i=0,k=0; //scanf terminates at every white character, must be called by a While // "i" tells where you are in msg (which is overwritten each time) // "k" tells where you are in crypt while(strcmp(msg,"@@@")) { scanf("%s",msg); i=0; while(msg[i]!='\0') { fscanf(keyfile,"%c", &c_aux); fprintf(crypt,"%c",msg[i]^c_aux); i++; k++; } fscanf(keyfile,"%c",&c_aux); fprintf(crypt,"%c",' '^c_aux); k++; } while (k<4096){ // fills the message with @s fscanf(keyfile,"%c",&c_aux); fprintf(crypt,"%c",'@'^c_aux); k++;} fclose(crypt); }