implemented keyLength

This commit is contained in:
Václav Šmejkal 2022-05-03 18:37:28 +02:00
parent e85a14b253
commit 61ce5d0c1b
3 changed files with 13 additions and 15 deletions

View File

@ -11,15 +11,14 @@ char*
decryptText(char *text, char *key)
{
//CHECK FOR INVALID key
if (strlen(key) < KEY_LENGTH)
if (strlen(key) < getKeyLength())
{
fprintf(stderr, "Key must be at least %d characters long!\n", KEY_LENGTH);
fprintf(stderr, "Key must be at least %d characters long!\n", getKeyLength());
exit(INVALID_KEY);
}
//REDEFINE KEY_LENGTH
#undef KEY_LENGTH
#define KEY_LENGTH strlen(key)
//REDEFINE keyLength
setKeyLength(strlen(key));
//VARIABLES
char *returningText;

View File

@ -18,7 +18,7 @@ encryptText(char *text, char *keyNew)
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
//VARIABLES
char *key = malloc(KEY_LENGTH);
char *key = malloc(getKeyLength());
char *returningText;
char *textBuffer;
int *textKeyChain = malloc(strlen(text) * sizeof(int));
@ -26,23 +26,22 @@ encryptText(char *text, char *keyNew)
if (keyNew != NULL)
{
if (strlen(keyNew) < KEY_LENGTH)
if (strlen(keyNew) < getKeyLength())
{
fprintf(stderr, "Key must be at least %d characters long!\n", KEY_LENGTH);
fprintf(stderr, "Key must be at least %d characters long!\n", getKeyLength());
exit(INVALID_KEY);
}
strcpy(key, keyNew);
//REDEFINE KEY_LENGTH
#undef KEY_LENGTH
#define KEY_LENGTH strlen(key)
//REDEFINE keyLength
setKeyLength(strlen(key));
goto skipKey;
}
//LOAD KEY
for (int i = 0; i < KEY_LENGTH; i++)
for (int i = 0; i < getKeyLength(); i++)
{
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
numberBuffer = (rand() % 52) + 1;

View File

@ -103,10 +103,10 @@ generateTextKeyChain(char key[], int *textKeyChain, int textKeyChainSize)
{
numberBuffer = i;
//CHECK, IF numberBuffer ISN'T GREATER THAN KEY_LENGTH AND CUT UNUSED LENGTH
while (numberBuffer >= KEY_LENGTH)
//CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT UNUSED LENGTH
while (numberBuffer >= getKeyLength())
{
numberBuffer -= KEY_LENGTH;
numberBuffer -= getKeyLength();
}
//FILL textKeyChain