diff options
Diffstat (limited to 'old_code/read_crypt.c')
-rw-r--r-- | old_code/read_crypt.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/old_code/read_crypt.c b/old_code/read_crypt.c new file mode 100644 index 0000000..af3a7c0 --- /dev/null +++ b/old_code/read_crypt.c @@ -0,0 +1,43 @@ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> + +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); +} |