added elapsedTime to outputFlags

this returns elapsed time in microseconds
This commit is contained in:
Václav Šmejkal 2022-05-30 19:09:47 +02:00
parent 69867cc0ba
commit 9823b5044a
No known key found for this signature in database
GPG Key ID: FD749A97DF2D5E19
5 changed files with 34 additions and 3 deletions

View File

@ -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

View File

@ -1,6 +1,8 @@
#ifndef WHY2_MISC_H
#define WHY2_MISC_H
#include <sys/time.h>
#include <why2/flags.h>
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

View File

@ -3,12 +3,18 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <why2/flags.h>
#include <why2/misc.h>
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

View File

@ -4,12 +4,19 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <why2/flags.h>
#include <why2/misc.h>
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

View File

@ -2,6 +2,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <curl/curl.h>
#include <json-c/json.h>
@ -223,3 +224,8 @@ 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;
}