moved pseudo-random seed generation to generateKey
This commit is contained in:
parent
80dd838ca8
commit
90eef0bb21
@ -53,14 +53,7 @@ outputFlags encryptText(char *text, char *keyNew)
|
|||||||
char *returningText;
|
char *returningText;
|
||||||
char *textBuffer = malloc(1);
|
char *textBuffer = malloc(1);
|
||||||
int *textKeyChain = malloc(sizeof(int) * strlen(text));
|
int *textKeyChain = malloc(sizeof(int) * strlen(text));
|
||||||
int numberBuffer;
|
int numberBuffer = 0;
|
||||||
FILE *fileBuffer;
|
|
||||||
|
|
||||||
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
|
||||||
fileBuffer = fopen("/dev/urandom", "r");
|
|
||||||
(void) (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) + 1); //TODO: Try to create some function for processing exit value
|
|
||||||
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
|
|
||||||
srand(numberBuffer);
|
|
||||||
|
|
||||||
if (keyNew != NULL)
|
if (keyNew != NULL)
|
||||||
{
|
{
|
||||||
@ -135,7 +128,6 @@ outputFlags encryptText(char *text, char *keyNew)
|
|||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
free(textKeyChain);
|
free(textKeyChain);
|
||||||
free(textBuffer);
|
free(textBuffer);
|
||||||
fclose(fileBuffer);
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
|
|
||||||
|
boolean seedSet = 0; //DO NOT FUCKING TOUCH THIS!!!
|
||||||
|
|
||||||
double multiply_cb(int a, int b) { return a * b; }
|
double multiply_cb(int a, int b) { return a * b; }
|
||||||
double subtract_cb(int a, int b) { return a - b; }
|
double subtract_cb(int a, int b) { return a - b; }
|
||||||
double sum_cb(int a, int b) { return a + b; }
|
double sum_cb(int a, int b) { return a + b; }
|
||||||
@ -392,6 +394,21 @@ void generateKey(char *key, int keyLength)
|
|||||||
{
|
{
|
||||||
int numberBuffer;
|
int numberBuffer;
|
||||||
|
|
||||||
|
if (!seedSet)
|
||||||
|
{
|
||||||
|
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
||||||
|
FILE *fileBuffer;
|
||||||
|
|
||||||
|
fileBuffer = fopen("/dev/urandom", "r");
|
||||||
|
(void) (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) + 1); //TODO: Try to create some function for processing exit value
|
||||||
|
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
|
||||||
|
srand(numberBuffer);
|
||||||
|
|
||||||
|
fclose(fileBuffer);
|
||||||
|
|
||||||
|
seedSet = 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < keyLength; i++)
|
for (int i = 0; i < keyLength; i++)
|
||||||
{
|
{
|
||||||
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
|
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
|
||||||
|
Loading…
x
Reference in New Issue
Block a user