implemented flags & created checking for valid key

This commit is contained in:
Václav Šmejkal 2022-03-08 19:46:19 +01:00
parent f7384e598c
commit f9af3884ee

View File

@ -4,11 +4,17 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "../include/flags.h"
char *decryptText(char *text, char *key) char *decryptText(char *text, char *key)
{ {
//CONSTS //CHECK FOR INVALID key
const int KEY_LENGTH = strlen(key); if (strlen(key) != KEY_LENGTH)
{
fprintf(stderr, "Key must be 50 characters long!\n");
exit(INVALID_KEY);
}
//VARIABLES //VARIABLES
char *returningText; char *returningText;
int numberBuffer; int numberBuffer;
@ -19,7 +25,7 @@ char *decryptText(char *text, char *key)
//GET LENTGH OF returningText AND textKeyChain //GET LENTGH OF returningText AND textKeyChain
for (int i = 0; i < strlen(text); i++) for (int i = 0; i < strlen(text); i++)
{ {
if (text[i] == '.') numberBuffer++; if (text[i] == ENCRYPTION_SEPARATOR) numberBuffer++;
} }
//SET LENGTH //SET LENGTH
@ -59,7 +65,7 @@ char *decryptText(char *text, char *key)
//GET LENGTH OF EACH CHARACTER //GET LENGTH OF EACH CHARACTER
for (int j = 0; j < strlen(text); j++) for (int j = 0; j < strlen(text); j++)
{ {
if (text[j] == '.') break; if (text[j] == ENCRYPTION_SEPARATOR) break;
numberBuffer++; numberBuffer++;
} }