preventing encrypted bytes from being zero

This commit is contained in:
Václav Šmejkal 2024-02-24 18:14:39 +01:00
parent 23f7019883
commit 226f9b3759
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 17 additions and 4 deletions

View File

@ -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 returning_text = why2_calloc(number_buffer + 1, sizeof(char)); //ALLOCATE
//SET LENGTH //SET LENGTH
returning_text[0] = strlen(text) & 0x7f; returning_text[0] = (strlen(text) & 0x7f) + 1; //+1 BECAUSE WE DON'T WANT \0
returning_text[1] = strlen(text) >> 7; returning_text[1] = (strlen(text) >> 7) + 1;
//PUT THE text_key_chain INTO returning_text DIRECTLY //PUT THE text_key_chain INTO returning_text DIRECTLY
for (unsigned long i = 0; i < strlen(text); i++) for (unsigned long i = 0; i < strlen(text); i++)
{ {
//BUILD returning_text
returning_text[2 + (i * 2)] = text_key_chain[i] & 0x7f; 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]--;
}
}
} }
} }

View File

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