#include #include #include int main(int argc, char* argv[]) { FILE* mess = fopen(argv[1], "r"); FILE* pad = fopen(argv[2], "r+"); FILE* critt = fopen(argv[3],"w"); fseek(mess, 0L, SEEK_END); long mess_size = ftell(mess); rewind(mess); fseek(pad, 0L, SEEK_END); long pad_size = ftell(pad); fseek(pad, (pad_size - mess_size), SEEK_SET); int i = 1; char a, b; while(i != EOF) { i = fscanf(mess, "%c", &a); fscanf(pad, "%c", &b); if(i != EOF) { fprintf(critt, "%c", a^b); } } /* The truncate function "rosicchia" la parte di chiave utilizzata */ ftruncate(fileno(pad), (pad_size - mess_size)); fseek(pad, 0L, SEEK_END); long new_pad_size = ftell(pad); fclose(mess); fclose(pad); fclose(critt); printf("Message length is %li bytes \n", mess_size); printf("Pad length was %li bytes \n", pad_size); printf("Pad length is now %li bytes \n", new_pad_size); printf("Pad length should now be %li bytes \n", (pad_size - mess_size)); exit(EXIT_SUCCESS); }