From 6a3f0053214f1194734ad8326ed66403bfe6b649 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 21 Nov 2024 20:56:18 +0100 Subject: [PATCH] implemented padding in decrypter FUCKKKKK remember how I mentioned that creating padding in encrypter was pain? This, compared to the encrypter is like getting stuck up your ass and getting it shaked by a fucking gorilla compared to stepping on a lego brick. FUCK. --- src/core/lib/decrypter.c | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index c2c2e88..3e8b3ad 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -23,7 +23,9 @@ along with this program. If not, see . #include #include +#include #include +#include #include #include @@ -175,6 +177,59 @@ why2_output_flags why2_decrypt_text(char *text, char *key) returning_text[i] = text_key_chain[i]; } + //REMOVE PADDING + if (why2_get_flags().padding > 0) + { + why2_list_t split_text = WHY2_LIST_EMPTY; //LIST OF returning_text SPLIT INTO CHARS + + //ADD CHARS + for (unsigned long i = 0; i < strlen(returning_text); i++) + { + why2_list_push(&split_text, &(returning_text[i]), sizeof(returning_text[i])); //ADD + } + + //OBTAIN SEED FROM key_new + srand(why2_sum_segment(key_new)); + + //GET RANDOM SEQUENCE USED IN ENCRYPTION + why2_list_t random_sequence = WHY2_LIST_EMPTY; + for (unsigned long i = 0; i < why2_get_flags().padding; i++) + { + int rand_buffer = rand(); + why2_list_push(&random_sequence, &rand_buffer, sizeof(int)); //ADD + } + why2_list_reverse(&random_sequence, sizeof(int)); //REVERSE + + //REMOVE PADDING FROM split_text LIST + for (unsigned long i = 0; i < why2_get_flags().padding; i++) + { + unsigned long random_position = (unsigned long) (*(int*) random_sequence.head -> value % (why2_list_get_size(&split_text) - 1)); //GET RANDOM POSITION + + //REMOVE FROM THE LIST + why2_list_remove_at(&split_text, random_position); + + //DEALLOCATION + why2_list_remove_at(&random_sequence, 0); + } + + //PUT PADDED TEXT INTO text_new + returning_text = why2_recalloc(returning_text, why2_list_get_size(&split_text) + 1, sizeof(char)); + why2_node_t *buffer = split_text.head; + why2_node_t *buffer_2; + unsigned long index_buffer = 0; + + do + { + returning_text[index_buffer++] = *(char*) buffer -> value; //COPY VALUE + + buffer_2 = buffer; + buffer = buffer -> next; //ITER + + why2_deallocate(buffer_2 -> value); //DEALLOCATION + why2_deallocate(buffer_2); //DEALLOCATION + } while (buffer != NULL); + } + //GET FINISH TIME gettimeofday(&finish_time, NULL);