From abbe519ab49d51e91a8cf51a027beec9e276b725 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Mon, 30 May 2022 18:01:21 +0200 Subject: [PATCH] added unusedKeySize to outputFlags this returns positive number, which represents how many chars from key are unused --- include/flags.h | 1 + include/misc.h | 1 + src/lib/decrypter.c | 3 ++- src/lib/encrypter.c | 3 ++- src/lib/misc.c | 12 ++++++++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/flags.h b/include/flags.h index 95de818..8909945 100644 --- a/include/flags.h +++ b/include/flags.h @@ -32,6 +32,7 @@ typedef struct { char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *usedKey; //VARIABLE FOR USED/GENERATED KEY + unsigned long unusedKeySize; } outputFlags; //VARIABLES diff --git a/include/misc.h b/include/misc.h index 31cea79..2ac7776 100644 --- a/include/misc.h +++ b/include/misc.h @@ -9,5 +9,6 @@ void deallocateOutput(outputFlags flags); //DEALLOCATES flags void checkKey(char *key, inputFlags flags); //CHECKS IF KEY IS VALID void checkText(char *text, inputFlags flags); //CHECKS IF TEXT IS VALID unsigned long countIntLength(int number); //RETURNS LENGTH OF number +unsigned long countUnusedKeySize(char *text, char *key); //COUNT unusedKeySize #endif diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index 6604268..285059c 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -96,7 +96,8 @@ outputFlags decryptText(char *text, char *keyNew, inputFlags flags) outputFlags output = { returningText, //DECRYPTED TEXT - key //USED KEY + key, //USED KEY + countUnusedKeySize(text, key) }; //DEALLOCATION diff --git a/src/lib/encrypter.c b/src/lib/encrypter.c index 5647596..6c97b95 100644 --- a/src/lib/encrypter.c +++ b/src/lib/encrypter.c @@ -116,7 +116,8 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags) outputFlags output = { returningText, //ENCRYPTED TEXT - key //GENERATED/USED KEY + key, //GENERATED/USED KEY + countUnusedKeySize(text, key) // NUMBER OF UNUSED CHARS IN KEY }; //DEALLOCATION diff --git a/src/lib/misc.c b/src/lib/misc.c index f0206e5..5d4a145 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -211,3 +211,15 @@ unsigned long countIntLength(int number) return returning; } + +unsigned long countUnusedKeySize(char *text, char *key) +{ + unsigned long returning = 0; + + if (strlen(key) / 2 > strlen(text)) + { + returning = strlen(key) - 2 * strlen(text); + } + + return returning; +} \ No newline at end of file