moved encryption key generation to misc.c

This commit is contained in:
Václav Šmejkal 2022-12-09 16:59:12 +01:00
parent 7b432df61d
commit acaa7430b8
No known key found for this signature in database
GPG Key ID: FD749A97DF2D5E19
3 changed files with 28 additions and 24 deletions

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h>
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

View File

@ -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));

View File

@ -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';
}