diff --git a/include/misc.h b/include/misc.h index 639e8c6..9878c51 100644 --- a/include/misc.h +++ b/include/misc.h @@ -24,6 +24,7 @@ along with this program. If not, see . #include void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION +void generateKey(char *key, int keyLength); //GENERATE ENCRYPTION KEY void deallocateOutput(outputFlags flags); //DEALLOCATES flags boolean checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED boolean checkKey(char *key); //CHECKS IF KEY IS VALID diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index cb186fb..6486f9e 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -74,33 +74,11 @@ outputFlags encryptText(char *text, char *keyNew) //REDEFINE keyLength setKeyLength(strlen(key)); - - goto skipKey; - } - - //LOAD KEY - for (int i = 0; i < (int) getKeyLength(); i++) + } else //LOAD KEY { - //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 - numberBuffer = (rand() % 52) + 1; - - //GET CHAR FROM numberBuffer - if (numberBuffer > 26) - { - numberBuffer += 70; - } - else - { - numberBuffer += 64; - } - - key[i] = (char) numberBuffer; + generateKey(key, getKeyLength()); } - key[getKeyLength()] = '\0'; - - skipKey: - //LOAD textKeyChain generateTextKeyChain(key, textKeyChain, strlen(text)); diff --git a/src/core/lib/misc.c b/src/core/lib/misc.c index a940e6e..496880d 100644 --- a/src/core/lib/misc.c +++ b/src/core/lib/misc.c @@ -386,4 +386,29 @@ unsigned long countRepeatedKeySize(char *text, char *key) unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime) { return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec; +} + +void generateKey(char *key, int keyLength) +{ + int numberBuffer; + + for (int i = 0; i < keyLength; i++) + { + //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 + numberBuffer = (rand() % 52) + 1; + + //GET CHAR FROM numberBuffer + if (numberBuffer > 26) + { + numberBuffer += 70; + } + else + { + numberBuffer += 64; + } + + key[i] = (char) numberBuffer; + } + + key[getKeyLength()] = '\0'; } \ No newline at end of file