From 226f9b3759658f4356c851f2857430907540e2be Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 24 Feb 2024 18:14:39 +0100 Subject: [PATCH] preventing encrypted bytes from being zero --- src/core/lib/encrypter.c | 19 ++++++++++++++++--- src/core/lib/utils/misc.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index d6d0cef..8f0eea0 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -119,14 +119,27 @@ why2_output_flags why2_encrypt_text(char *text, char *key_new) returning_text = why2_calloc(number_buffer + 1, sizeof(char)); //ALLOCATE //SET LENGTH - returning_text[0] = strlen(text) & 0x7f; - returning_text[1] = strlen(text) >> 7; + returning_text[0] = (strlen(text) & 0x7f) + 1; //+1 BECAUSE WE DON'T WANT \0 + returning_text[1] = (strlen(text) >> 7) + 1; //PUT THE text_key_chain INTO returning_text DIRECTLY for (unsigned long i = 0; i < strlen(text); i++) { + //BUILD returning_text returning_text[2 + (i * 2)] = text_key_chain[i] & 0x7f; - returning_text[3 + (i * 2)] = (text_key_chain[i] >> 7)| ((text_key_chain[i] < 0) ? 0x80 : 0); + returning_text[3 + (i * 2)] = (text_key_chain[i] >> 7) | ((text_key_chain[i] < 0) ? 0x80 : 0); + + for (unsigned long j = 2 + (i * 2); j <= 3 + (i * 2); j++) + { + //ENSURE THERE IS NO \0 + if (returning_text[j] > 0) + { + returning_text[j]++; + } else + { + returning_text[j]--; + } + } } } diff --git a/src/core/lib/utils/misc.c b/src/core/lib/utils/misc.c index 1f0d637..7b1b21a 100644 --- a/src/core/lib/utils/misc.c +++ b/src/core/lib/utils/misc.c @@ -469,5 +469,5 @@ char *why2_replace(char *string, char *old, char *new) //CODE FROM: https://www. unsigned short why2_byte_format_length(char *s) { - return (s[1] << 7) | s[0]; //ADD THE FIRST TWO INDEXES TOGETHER TO GET LENGTH + return ((s[1] - 1) << 7) | (s[0] - 1); //ADD THE FIRST TWO INDEXES TOGETHER TO GET LENGTH } \ No newline at end of file