diff --git a/includes/decrypt.hpp b/includes/decrypt.hpp index c47f9dd..80dcc1b 100644 --- a/includes/decrypt.hpp +++ b/includes/decrypt.hpp @@ -1,6 +1,6 @@ #ifndef DECRYPT_HPP #define DECRYPT_HPP -unsigned char *decrypt(char* encyrpted_text, char *passphrase); +unsigned char *decrypt(char* encrypted_text, char *passphrase); #endif \ No newline at end of file diff --git a/src/decrypt.cpp b/src/decrypt.cpp index ee58800..39400df 100644 --- a/src/decrypt.cpp +++ b/src/decrypt.cpp @@ -2,7 +2,7 @@ #include "../lib/Blowfish/blowfish.h" #include -unsigned char *decrypt(char* encyrpted_text, char *passphrase){ +unsigned char *decrypt(char* encrypted_text, char *passphrase){ if(passphrase == NULL){ passphrase = "mypassphrase"; }else{ @@ -11,12 +11,11 @@ unsigned char *decrypt(char* encyrpted_text, char *passphrase){ exit(0); } } - unsigned char unsigned_content[strlen(encyrpted_text) + 5] = {0} ; + + unsigned char unsigned_content[strlen(encrypted_text) + 5] = {0} ; int i = 0 ; - while(i < strlen(encyrpted_text)){ - unsigned_content[i] = encyrpted_text[i]; - i++; - } + strncpy((char *)unsigned_content, encrypted_text, strlen(encrypted_text)); +// converting to unsigned keys i = 0; unsigned char unsigned_key[strlen(passphrase) + 5] = {0} ; while(i < strlen(passphrase)){ diff --git a/src/embed.cpp b/src/embed.cpp index 089fe29..0a6d273 100644 --- a/src/embed.cpp +++ b/src/embed.cpp @@ -78,13 +78,13 @@ void embed(char* coverfile, char* embedingfile, char* passphrase, char* outputfi // when reading the header using extract.cpp the x added here will be removed and the strings will be converted to ints to get the right values // reading these header maybe will crash when using bigest files "more than 9999" so this is temporarely until i change it while(i < 7){ - if(s_array[i] < 9){ + if(s_array[i] <= 9){ string_cover_content.insert(f , std::to_string(s_array[i]) + "xxx"); - }else if(s_array[i] < 99){ + }else if(s_array[i] <= 99){ string_cover_content.insert(f , std::to_string(s_array[i]) + "xx"); // the x appended to the file are used to make every int take 4 bytes, i thought adding null bytes would be better but null bytes are used as string terminators, x's are used temporarily until i find a better solution - }else if(s_array[i] < 999){ + }else if(s_array[i] <= 999){ string_cover_content.insert(f , std::to_string(s_array[i]) + "x"); - }else if(s_array[i] < 9999){ + }else if(s_array[i] <= 9999){ string_cover_content.insert(f , std::to_string(s_array[i])); } i++; diff --git a/src/extract.cpp b/src/extract.cpp index 53d918d..27f398b 100644 --- a/src/extract.cpp +++ b/src/extract.cpp @@ -102,11 +102,11 @@ void extract(char* stegfile, char* passphrase, char* outputfile, bool encryption container += d ; char encrypted_text[container.length() + 10]; strcpy(encrypted_text, container.c_str()); - encrypted_text[header.s_sizef] = '\0'; - std::cout << encrypted_text; + encrypted_text[header.s_sizef +1] = '\0'; // decrypting the data extracted char *con = encrypted_text ; unsigned char* unsig_container = decrypt(con, passphrase); + std::cout << unsig_container; // storing it into a file FILE *output; output = fopen(outputfile, "w");