From a11415b949208b44a13a60834417bed85584cf75 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 6 May 2022 17:43:00 +0200 Subject: [PATCH] implemented inputFlags & outputFlags --- include/decrypter.h | 4 +++- include/encrypter.h | 4 +++- include/flags.h | 6 +++--- src/app/main.c | 12 +++++++----- src/lib/decrypter.c | 12 +++++++++--- src/lib/encrypter.c | 14 +++++++++----- src/lib/test/main.c | 17 ++++++++--------- 7 files changed, 42 insertions(+), 27 deletions(-) diff --git a/include/decrypter.h b/include/decrypter.h index a56e547..797b8d9 100644 --- a/include/decrypter.h +++ b/include/decrypter.h @@ -1,6 +1,8 @@ #ifndef WHY2_DECRYPTER_H #define WHY2_DECRYPTER_H -char *decryptText(char *text, char *key); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED +#include + +outputFlags decryptText(char *text, char *key, inputFlags flags); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED #endif \ No newline at end of file diff --git a/include/encrypter.h b/include/encrypter.h index c4dd49f..b0e4640 100644 --- a/include/encrypter.h +++ b/include/encrypter.h @@ -1,6 +1,8 @@ #ifndef WHY2_ENCRYPTER_H #define WHY2_ENCRYPTER_H -char *encryptText(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED +#include + +outputFlags encryptText(char *text, char *keyNew, inputFlags flags); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED #endif \ No newline at end of file diff --git a/include/flags.h b/include/flags.h index b9489aa..744af00 100644 --- a/include/flags.h +++ b/include/flags.h @@ -23,17 +23,17 @@ #define DEPRECATED __attribute__((deprecated)) -typedef struct inputFlag +typedef struct input { int skipCheck; int noOutput; } inputFlags; -typedef struct outputFlag +typedef struct output { char *outputText; char *usedKey; -} *outputFlags; +} outputFlags; //VARIABLES static int keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS < diff --git a/src/app/main.c b/src/app/main.c index 01ad7a6..09077c3 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -6,10 +6,13 @@ int main(void) { - setNoOutput(1); - setSkipCheck(1); + inputFlags flags = + { + 1, //SKIP CHECK + 1 //NO OUTPUT + }; - char *encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL); + outputFlags encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL, flags); printf ( @@ -21,9 +24,8 @@ int main(void) "If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \n" "Thank you so much for supporting this project!\n" - , TEXT_TO_ENCRYPT, encryptedText + , TEXT_TO_ENCRYPT, encryptedText.outputText ); - free(encryptedText); return 0; } \ No newline at end of file diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index 98f3bd5..af766aa 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -7,8 +7,7 @@ #include #include -char* -decryptText(char *text, char *key) +outputFlags decryptText(char *text, char *key, inputFlags flags) { //CHECK FOR INVALID key if (strlen(key) < getKeyLength()) @@ -83,8 +82,15 @@ decryptText(char *text, char *key) returningText[i] = (char) textKeyChain[i]; } + //LOAD output + outputFlags output = + { + returningText, //DECRYPTED TEXT + key //USED KEY + }; + //DEALLOCATION free(textKeyChain); - return returningText; + return output; } diff --git a/src/lib/encrypter.c b/src/lib/encrypter.c index 73fc140..81db50d 100644 --- a/src/lib/encrypter.c +++ b/src/lib/encrypter.c @@ -9,8 +9,7 @@ #include #include -char* -encryptText(char *text, char *keyNew) +outputFlags encryptText(char *text, char *keyNew, inputFlags flags) { //CHECK FOR ACTIVE VERSION checkVersion(); @@ -58,8 +57,6 @@ encryptText(char *text, char *keyNew) key[i] = (char) numberBuffer; } - if (!getNoOutput()) printf("Your key is: %s\n!!! SAVE IT SOMEWHERE !!!\n\n", key); - skipKey: //LOAD textKeyChain @@ -98,8 +95,15 @@ encryptText(char *text, char *keyNew) free(textBuffer); } + //LOAD output + outputFlags output = + { + returningText, //ENCRYPTED TEXT + key //GENERATED/USED KEY + }; + //DEALLOCATION free(key); - return returningText; + return output; } diff --git a/src/lib/test/main.c b/src/lib/test/main.c index 6bd8568..13e3928 100644 --- a/src/lib/test/main.c +++ b/src/lib/test/main.c @@ -6,18 +6,18 @@ #include #include -int -main(int argc, char *argv[]) +int main(void) { - if (argc == 2 && strcmp(argv[1], "skipCheck") == 0) + inputFlags flags = { - setSkipCheck(1); - } + 1, //SKIP CHECK + 0, //NO OUTPUT + }; - char *text = encryptText(TEST_TEXT, TEST_KEY); - text = decryptText(text, TEST_KEY); + outputFlags encrypted = encryptText(TEST_TEXT, TEST_KEY, flags); + encrypted = decryptText(encrypted.outputText, TEST_KEY, flags); - if (strcmp(text, TEST_TEXT) == 0) + if (strcmp(encrypted.outputText, TEST_TEXT) == 0) { printf("Test successful!\n"); } @@ -27,6 +27,5 @@ main(int argc, char *argv[]) exit(1); } - free(text); return 0; }