implemented keyLength
This commit is contained in:
parent
e85a14b253
commit
61ce5d0c1b
@ -11,15 +11,14 @@ char*
|
|||||||
decryptText(char *text, char *key)
|
decryptText(char *text, char *key)
|
||||||
{
|
{
|
||||||
//CHECK FOR INVALID 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);
|
exit(INVALID_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
//REDEFINE KEY_LENGTH
|
//REDEFINE keyLength
|
||||||
#undef KEY_LENGTH
|
setKeyLength(strlen(key));
|
||||||
#define KEY_LENGTH strlen(key)
|
|
||||||
|
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
char *returningText;
|
char *returningText;
|
||||||
|
@ -18,7 +18,7 @@ encryptText(char *text, char *keyNew)
|
|||||||
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
||||||
|
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
char *key = malloc(KEY_LENGTH);
|
char *key = malloc(getKeyLength());
|
||||||
char *returningText;
|
char *returningText;
|
||||||
char *textBuffer;
|
char *textBuffer;
|
||||||
int *textKeyChain = malloc(strlen(text) * sizeof(int));
|
int *textKeyChain = malloc(strlen(text) * sizeof(int));
|
||||||
@ -26,23 +26,22 @@ encryptText(char *text, char *keyNew)
|
|||||||
|
|
||||||
if (keyNew != NULL)
|
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);
|
exit(INVALID_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(key, keyNew);
|
strcpy(key, keyNew);
|
||||||
|
|
||||||
//REDEFINE KEY_LENGTH
|
//REDEFINE keyLength
|
||||||
#undef KEY_LENGTH
|
setKeyLength(strlen(key));
|
||||||
#define KEY_LENGTH strlen(key)
|
|
||||||
|
|
||||||
goto skipKey;
|
goto skipKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOAD KEY
|
//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
|
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
|
||||||
numberBuffer = (rand() % 52) + 1;
|
numberBuffer = (rand() % 52) + 1;
|
||||||
|
@ -103,10 +103,10 @@ generateTextKeyChain(char key[], int *textKeyChain, int textKeyChainSize)
|
|||||||
{
|
{
|
||||||
numberBuffer = i;
|
numberBuffer = i;
|
||||||
|
|
||||||
//CHECK, IF numberBuffer ISN'T GREATER THAN KEY_LENGTH AND CUT UNUSED LENGTH
|
//CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT UNUSED LENGTH
|
||||||
while (numberBuffer >= KEY_LENGTH)
|
while (numberBuffer >= getKeyLength())
|
||||||
{
|
{
|
||||||
numberBuffer -= KEY_LENGTH;
|
numberBuffer -= getKeyLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
//FILL textKeyChain
|
//FILL textKeyChain
|
||||||
|
Loading…
x
Reference in New Issue
Block a user