diff options
author | Luke <luke@inventati.org> | 2016-06-09 19:35:01 +0200 |
---|---|---|
committer | Luke <luke@inventati.org> | 2016-06-09 19:35:01 +0200 |
commit | 91facf3cb62d5f8b102d2f567f82b4d5c4b01f74 (patch) | |
tree | e2a658d1cbdd86668ff0eb42c6d3527c03414d73 | |
parent | a85a21d3084cdb6d10bb8dd6d833a4085344418a (diff) | |
download | onetimebluh-91facf3cb62d5f8b102d2f567f82b4d5c4b01f74.tar.gz onetimebluh-91facf3cb62d5f8b102d2f567f82b4d5c4b01f74.tar.bz2 onetimebluh-91facf3cb62d5f8b102d2f567f82b4d5c4b01f74.zip |
Added read_crypt.c. It does what it says
-rw-r--r-- | read_crypt.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/read_crypt.c b/read_crypt.c new file mode 100644 index 0000000..af3a7c0 --- /dev/null +++ b/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); +} |