2022-03-20 18:12:25 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-04-27 19:18:30 +02:00
|
|
|
#include <string.h>
|
2022-03-20 18:12:25 +01:00
|
|
|
|
2022-05-12 17:12:33 +02:00
|
|
|
#include <why2.h>
|
2022-03-20 18:12:25 +01:00
|
|
|
|
2022-05-12 18:50:58 +02:00
|
|
|
int main(void)
|
2022-03-20 18:12:25 +01:00
|
|
|
{
|
2022-05-25 17:44:53 +02:00
|
|
|
//VARIABLES
|
2022-05-29 17:00:43 +02:00
|
|
|
char *textBuffer = malloc(128);
|
|
|
|
char *keyBuffer;
|
2022-07-23 15:37:54 +02:00
|
|
|
char *statusBuffer;
|
|
|
|
char *outputBuffer = malloc(1); //THIS IS TEMP ALLOCATION
|
2022-05-24 18:09:35 +02:00
|
|
|
int exitCode = 0;
|
2022-05-30 19:13:43 +02:00
|
|
|
unsigned long timeBuffer;
|
2022-07-23 15:37:54 +02:00
|
|
|
FILE *outputStreamBuffer = stdout;
|
2022-05-08 20:02:47 +02:00
|
|
|
|
2022-05-25 17:44:53 +02:00
|
|
|
//FLAGS
|
2022-05-06 17:43:00 +02:00
|
|
|
inputFlags flags =
|
2022-04-29 18:00:38 +02:00
|
|
|
{
|
2022-05-23 18:02:59 +02:00
|
|
|
0, //SKIP CHECK
|
2022-05-06 17:43:00 +02:00
|
|
|
0, //NO OUTPUT
|
2022-07-10 17:51:31 +02:00
|
|
|
0 //UPDATE
|
2022-05-06 17:43:00 +02:00
|
|
|
};
|
2022-04-29 18:00:38 +02:00
|
|
|
|
2022-07-10 18:17:42 +02:00
|
|
|
//SET FLAGS
|
|
|
|
setFlags(flags);
|
|
|
|
|
2022-05-25 18:01:13 +02:00
|
|
|
//SET KEY_LENGTH TO 100
|
|
|
|
setKeyLength(100);
|
2022-06-13 18:13:27 +02:00
|
|
|
keyBuffer = malloc(getKeyLength() + 1);
|
2022-05-25 17:47:46 +02:00
|
|
|
|
2022-06-18 18:34:27 +02:00
|
|
|
//SET ENCRYPTION_SEPARATOR TO '|'
|
|
|
|
setEncryptionSeparator('|');
|
|
|
|
|
2022-07-23 15:37:54 +02:00
|
|
|
//SET outputBuffer to NULL
|
|
|
|
outputBuffer[0] = '\0';
|
|
|
|
|
2022-05-30 19:13:43 +02:00
|
|
|
//ENCRYPT
|
2022-07-10 18:17:42 +02:00
|
|
|
outputFlags encrypted = encryptText(TEST_TEXT, NULL);
|
2022-05-08 20:02:47 +02:00
|
|
|
|
2022-05-29 17:00:43 +02:00
|
|
|
strcpy(textBuffer, encrypted.outputText); //GET ENCRYPTED TEXT
|
|
|
|
strcpy(keyBuffer, encrypted.usedKey); //GET KEY
|
2022-05-30 19:13:43 +02:00
|
|
|
timeBuffer = encrypted.elapsedTime; //GET TIME 1
|
2022-05-08 20:02:47 +02:00
|
|
|
|
2022-05-29 17:00:43 +02:00
|
|
|
//DEALLOCATE BUFFER
|
|
|
|
deallocateOutput(encrypted);
|
|
|
|
|
2022-05-30 19:13:43 +02:00
|
|
|
//DECRYPT
|
2022-07-10 18:17:42 +02:00
|
|
|
encrypted = decryptText(textBuffer, keyBuffer);
|
2022-03-20 18:12:25 +01:00
|
|
|
|
2022-05-30 19:13:43 +02:00
|
|
|
timeBuffer += encrypted.elapsedTime; //GET TIME 1
|
|
|
|
|
2022-05-25 17:44:53 +02:00
|
|
|
//COMPARE DIFFERENCE
|
2022-07-23 15:37:54 +02:00
|
|
|
if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) //SUCCESS
|
2022-04-27 19:18:30 +02:00
|
|
|
{
|
2022-07-23 15:37:54 +02:00
|
|
|
statusBuffer = malloc(11);
|
|
|
|
strcpy(statusBuffer, "successful");
|
2022-04-27 19:18:30 +02:00
|
|
|
}
|
2022-07-23 15:37:54 +02:00
|
|
|
else //FAILURE
|
2022-04-27 19:18:30 +02:00
|
|
|
{
|
2022-07-23 15:37:54 +02:00
|
|
|
statusBuffer = malloc(8);
|
|
|
|
strcpy(statusBuffer, "failed");
|
|
|
|
|
|
|
|
outputBuffer = realloc(outputBuffer, strlen(encrypted.outputText) + 6);
|
|
|
|
sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.outputText);
|
|
|
|
|
|
|
|
outputStreamBuffer = stderr;
|
2022-05-24 18:09:35 +02:00
|
|
|
exitCode = 1;
|
2022-04-27 19:18:30 +02:00
|
|
|
}
|
2022-03-20 18:12:25 +01:00
|
|
|
|
2022-07-23 15:37:54 +02:00
|
|
|
//PRINT OUTPUT
|
|
|
|
fprintf
|
|
|
|
(
|
|
|
|
outputStreamBuffer,
|
|
|
|
|
|
|
|
"Test %s!\n\n"
|
|
|
|
|
|
|
|
"TEXT: \t\t\"%s\"\n%s"
|
|
|
|
"OUTPUT: \t\"%s\"\n"
|
|
|
|
"KEY: \t\t\"%s\"\n"
|
|
|
|
"TIME: \t\t\"%lums\"\n"
|
|
|
|
"UNUSED KEY: \t\"%lu\"\n"
|
|
|
|
"EXIT CODE: \t\"%d\"\n"
|
|
|
|
|
|
|
|
, statusBuffer, TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.exitCode
|
|
|
|
);
|
|
|
|
|
2022-05-08 19:56:16 +02:00
|
|
|
//DEALLOCATION
|
2022-05-29 17:00:43 +02:00
|
|
|
free(textBuffer);
|
|
|
|
free(keyBuffer);
|
2022-07-23 15:37:54 +02:00
|
|
|
free(statusBuffer);
|
2022-05-12 18:50:58 +02:00
|
|
|
deallocateOutput(encrypted);
|
2022-05-08 19:56:16 +02:00
|
|
|
|
2022-05-24 18:09:35 +02:00
|
|
|
return exitCode;
|
2022-04-26 19:05:57 +02:00
|
|
|
}
|