WHY2/src/lib/test/main.c

59 lines
1.4 KiB
C
Raw Normal View History

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
int main(void)
2022-03-20 18:12:25 +01:00
{
2022-05-25 17:44:53 +02:00
//VARIABLES
char *textBuffer = malloc(128);
char *keyBuffer;
2022-05-24 18:09:35 +02:00
int exitCode = 0;
unsigned long timeBuffer;
2022-05-25 17:44:53 +02:00
//FLAGS
2022-05-06 17:43:00 +02:00
inputFlags flags =
{
0, //SKIP CHECK
2022-05-06 17:43:00 +02:00
0, //NO OUTPUT
};
//SET KEY_LENGTH TO 100
setKeyLength(100);
keyBuffer = malloc(getKeyLength());
2022-05-25 17:47:46 +02:00
//ENCRYPT
outputFlags encrypted = encryptText(TEST_TEXT, NULL, flags);
strcpy(textBuffer, encrypted.outputText); //GET ENCRYPTED TEXT
strcpy(keyBuffer, encrypted.usedKey); //GET KEY
timeBuffer = encrypted.elapsedTime; //GET TIME 1
//DEALLOCATE BUFFER
deallocateOutput(encrypted);
//DECRYPT
encrypted = decryptText(textBuffer, keyBuffer, flags);
2022-03-20 18:12:25 +01:00
timeBuffer += encrypted.elapsedTime; //GET TIME 1
2022-05-25 17:44:53 +02:00
//COMPARE DIFFERENCE
2022-05-06 17:43:00 +02:00
if (strcmp(encrypted.outputText, TEST_TEXT) == 0)
2022-04-27 19:18:30 +02:00
{
printf("Test successful!\n\nTEXT: %s\nOUTPUT: %s\nKEY: %s\nTIME: %lums\nUNUSED KEY-CHARS: %lu\n", TEST_TEXT, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize);
2022-04-27 19:18:30 +02:00
}
else
{
2022-05-25 17:39:57 +02:00
fprintf(stderr, "Test failed!\n\n%s // %s\n", encrypted.outputText, TEST_TEXT);
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-05-08 19:56:16 +02:00
//DEALLOCATION
free(textBuffer);
free(keyBuffer);
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
}