implemented WHY2_OUTPUT_BYTE in decrypter

i choose literally the worst approach but YEAH...

...it doesn't work...

...it overflows...
This commit is contained in:
Václav Šmejkal 2024-02-24 21:05:09 +01:00
parent 226f9b3759
commit 9734749c3e
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -60,14 +60,70 @@ why2_output_flags why2_decrypt_text(char *text, char *key_new)
//VARIABLES //VARIABLES
char *returning_text; char *returning_text;
int number_buffer = 1; int number_buffer = 0;
int used_text_deallocation_buffer = 0; int used_text_deallocation_buffer = 0;
char *text_buffer = NULL; char *text_buffer = NULL;
int text_key_chainLength; int text_key_chainLength;
int *text_key_chain; int *text_key_chain;
char *key = why2_strdup(key_new); //COPY key_new TO key char *key = why2_strdup(key_new); //COPY key_new TO key
int *encrypted_text_key_chain; int *encrypted_text_key_chain;
char *used_text = why2_strdup(text); //COPY text TO used_text char *used_text = NULL; //COPY text TO used_text
if (why2_get_flags().format == WHY2_OUTPUT_BYTE)
{
//REBUILD THE BYTE FORMAT AS TEXT FORMAT
int *encrypted_input = why2_malloc(sizeof(int) * why2_byte_format_length(text));
char *text_copy = why2_strdup(text);
//GET ENCRYPTED NUMBERS
for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++)
{
for (unsigned short j = 2 + (i * 2); j <= 3 + (i * 2); j++)
{
//ENSURE THERE IS NO \0 (REVERSED)
if (text_copy[j] > 0)
{
text_copy[j]--;
} else
{
text_copy[j]++;
}
}
//PUT TOGETHER
encrypted_input[i] = (text_copy[3 + (i * 2)] << 7) | text_copy[2 + (i * 2)];
//ALSO COUNT REQUIRED SIZE
number_buffer += why2_count_int_length(encrypted_input[i]);
}
number_buffer += why2_byte_format_length(text_copy); //ADD THE SEPARATORS (I didn't remove one cause 1 index will be empty at used_text end)
used_text = why2_calloc(number_buffer, sizeof(char));
for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++)
{
number_buffer = why2_count_int_length(encrypted_input[i]);
text_buffer = why2_realloc(text_buffer, number_buffer + 1);
sprintf(text_buffer, "%d", encrypted_input[i]);
strcat(used_text, text_buffer);
if (i != why2_byte_format_length(text_copy) - 1)
{
used_text[strlen(used_text)] = why2_get_encryption_separator();
}
}
//DEALLOCATION
why2_deallocate(encrypted_input);
why2_deallocate(text_buffer);
why2_deallocate(text_copy);
} else if (why2_get_flags().format == WHY2_OUTPUT_TEXT)
{
used_text = why2_strdup(text);
}
number_buffer = 1;
//GET LENGTH OF returning_text AND text_key_chain //GET LENGTH OF returning_text AND text_key_chain
for (int i = 0; i < (int) strlen(used_text); i++) for (int i = 0; i < (int) strlen(used_text); i++)