moved encryption key generation to misc.c
This commit is contained in:
parent
7b432df61d
commit
acaa7430b8
@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
|
|
||||||
void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
|
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
|
void deallocateOutput(outputFlags flags); //DEALLOCATES flags
|
||||||
boolean checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED
|
boolean checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED
|
||||||
boolean checkKey(char *key); //CHECKS IF KEY IS VALID
|
boolean checkKey(char *key); //CHECKS IF KEY IS VALID
|
||||||
|
@ -74,32 +74,10 @@ outputFlags encryptText(char *text, char *keyNew)
|
|||||||
|
|
||||||
//REDEFINE keyLength
|
//REDEFINE keyLength
|
||||||
setKeyLength(strlen(key));
|
setKeyLength(strlen(key));
|
||||||
|
} else //LOAD KEY
|
||||||
goto skipKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
//LOAD KEY
|
|
||||||
for (int i = 0; i < (int) getKeyLength(); i++)
|
|
||||||
{
|
{
|
||||||
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
|
generateKey(key, getKeyLength());
|
||||||
numberBuffer = (rand() % 52) + 1;
|
|
||||||
|
|
||||||
//GET CHAR FROM numberBuffer
|
|
||||||
if (numberBuffer > 26)
|
|
||||||
{
|
|
||||||
numberBuffer += 70;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
numberBuffer += 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
key[i] = (char) numberBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
key[getKeyLength()] = '\0';
|
|
||||||
|
|
||||||
skipKey:
|
|
||||||
|
|
||||||
//LOAD textKeyChain
|
//LOAD textKeyChain
|
||||||
generateTextKeyChain(key, textKeyChain, strlen(text));
|
generateTextKeyChain(key, textKeyChain, strlen(text));
|
||||||
|
@ -387,3 +387,28 @@ unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTi
|
|||||||
{
|
{
|
||||||
return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec;
|
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';
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user