implemented keyLength
This commit is contained in:
parent
e85a14b253
commit
61ce5d0c1b
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user