diff --git a/include/flags.h b/include/flags.h index 8909945..e2b6937 100644 --- a/include/flags.h +++ b/include/flags.h @@ -32,7 +32,8 @@ typedef struct { char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *usedKey; //VARIABLE FOR USED/GENERATED KEY - unsigned long unusedKeySize; + unsigned long unusedKeySize; //VARIABLE FOR COUNT OF UNUSED CHARACTERS IN KEY + unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs } outputFlags; //VARIABLES diff --git a/include/misc.h b/include/misc.h index 2ac7776..5418111 100644 --- a/include/misc.h +++ b/include/misc.h @@ -1,6 +1,8 @@ #ifndef WHY2_MISC_H #define WHY2_MISC_H +#include + #include void checkVersion(inputFlags flags); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED @@ -10,5 +12,6 @@ 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 +unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS #endif diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index b5e4e00..b2e096c 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -3,12 +3,18 @@ #include #include #include +#include #include #include outputFlags decryptText(char *text, char *keyNew, inputFlags flags) { + //TIME VARIABLES + struct timeval startTime; + struct timeval finishTime; + gettimeofday(&startTime, NULL); + //CHECK FOR INVALID text checkText(text, flags); @@ -92,12 +98,16 @@ outputFlags decryptText(char *text, char *keyNew, inputFlags flags) returningText[i] = textKeyChain[i]; } + //GET FINISH TIME + gettimeofday(&finishTime, NULL); + //LOAD output outputFlags output = { returningText, //DECRYPTED TEXT key, //USED KEY - countUnusedKeySize(returningText, key) + countUnusedKeySize(returningText, key), // NUMBER OF UNUSED CHARS IN KEY + compareTimeMicro(startTime, finishTime) // ELAPSED TIME }; //DEALLOCATION diff --git a/src/lib/encrypter.c b/src/lib/encrypter.c index 6c97b95..117e047 100644 --- a/src/lib/encrypter.c +++ b/src/lib/encrypter.c @@ -4,12 +4,19 @@ #include #include #include +#include +#include #include #include outputFlags encryptText(char *text, char *keyNew, inputFlags flags) { + //TIME VARIABLES + struct timeval startTime; + struct timeval finishTime; + gettimeofday(&startTime, NULL); + //CHECK FOR INVALID text checkText(text, flags); @@ -112,12 +119,16 @@ outputFlags encryptText(char *text, char *keyNew, inputFlags flags) } } + //GET FINISH TIME + gettimeofday(&finishTime, NULL); + //LOAD output outputFlags output = { returningText, //ENCRYPTED TEXT key, //GENERATED/USED KEY - countUnusedKeySize(text, key) // NUMBER OF UNUSED CHARS IN KEY + countUnusedKeySize(text, key), // NUMBER OF UNUSED CHARS IN KEY + compareTimeMicro(startTime, finishTime) // ELAPSED TIME }; //DEALLOCATION diff --git a/src/lib/misc.c b/src/lib/misc.c index 5d4a145..528927a 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -222,4 +223,9 @@ unsigned long countUnusedKeySize(char *text, char *key) } return returning; +} + +unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime) +{ + return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec; } \ No newline at end of file