From 126565cf977b7ab2c84337b30c1ccfeaf5b7b20e Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 21 Nov 2024 20:50:41 +0100 Subject: [PATCH] preventing padding char from being 0 --- src/core/lib/encrypter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index 595056f..5719a65 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -99,8 +99,12 @@ why2_output_flags why2_encrypt_text(char *text, char *key) { unsigned long random_position = (unsigned long) (rand() % (why2_list_get_size(&split_text))); //GET RANDOM POSITION - char random_char; - why2_random(&random_char, sizeof(random_char)); //GENERATE COMPLETELY RANDOM CHARACTER + char random_char = 0; + for (int j = 0; j < WHY2_PADDING_NONZERO_TRIES && random_char == 0 ; j++) //GET RANDOM (EXCLUDING 0) + { + why2_random(&random_char, sizeof(random_char)); //GENERATE COMPLETELY RANDOM CHARACTER + } + if (random_char == 0) random_char = 1; //INSERT RANDOM VALUE why2_list_push_at(&split_text, random_position, &random_char, sizeof(random_char));