From 95ad46d62d45f73c12d0400e971e09e2a504ea3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ebest=C3=AD=C4=8Dek?= <44745014+SebestikCZ@users.noreply.github.com> Date: Sun, 20 Mar 2022 16:15:59 +0100 Subject: [PATCH] Delete src directory --- src/decrypter.c | 103 ---------------------------------------- src/encrypter.c | 123 ------------------------------------------------ src/test/main.c | 18 ------- 3 files changed, 244 deletions(-) delete mode 100644 src/decrypter.c delete mode 100644 src/encrypter.c delete mode 100644 src/test/main.c diff --git a/src/decrypter.c b/src/decrypter.c deleted file mode 100644 index 7162ae7..0000000 --- a/src/decrypter.c +++ /dev/null @@ -1,103 +0,0 @@ -#include "../include/decrypter.h" - -#include -#include -#include - -#include "../include/flags.h" - -char* -decryptText(char *text, char *key) -{ - //CHECK FOR INVALID key - if (strlen(key) != KEY_LENGTH) - { - fprintf(stderr, "Key must be 50 characters long!\n"); - exit(INVALID_KEY); - } - - //VARIABLES - char *returningText; - int numberBuffer; - char *textBuffer; - - numberBuffer = 1; - - //GET LENGHT OF returningText AND textKeyChain - for (int i = 0; i < strlen(text); i++) - { - if (text[i] == ENCRYPTION_SEPARATOR) numberBuffer++; - } - - //SET LENGTH - returningText = malloc(numberBuffer); - int textKeyChain[numberBuffer]; - int encryptedTextKeyChain[numberBuffer]; - - //LOAD textKeyChain - for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++) - { - numberBuffer = i; - - //CHECK, IF numberBuffer ISN'T GREATER THAN KEY_LENGTH AND CUT UNUSED LENGTH - while (numberBuffer >= KEY_LENGTH) - { - numberBuffer -= KEY_LENGTH; - } - - //FILL textKeyChain - if ((numberBuffer + 1) % 3 == 0) - { - textKeyChain[i] = key[numberBuffer] * key[numberBuffer + 1]; - } else if ((numberBuffer + 1) % 2 == 0) - { - textKeyChain[i] = key[numberBuffer] - key[numberBuffer + 1]; - } else - { - textKeyChain[i] = key[numberBuffer] + key[numberBuffer + 1]; - } - } - - //LOAD encryptedTextKeyChain - for (int i = 0; i < (sizeof(encryptedTextKeyChain) / sizeof(int)); i++) - { - numberBuffer = 0; - - //GET LENGTH OF EACH CHARACTER - for (int j = 0; j < strlen(text); j++) - { - if (text[j] == ENCRYPTION_SEPARATOR) break; - - numberBuffer++; - } - - textBuffer = malloc(numberBuffer); - - //LOAD textBuffer - for (int j = 0; j < strlen(text); j++) - { - textBuffer[j] = text[j]; - - if (numberBuffer == j) break; - } - - encryptedTextKeyChain[i] = atoi(textBuffer); - - text += numberBuffer + 1; - free(textBuffer); - } - - //DECRYPT TEXT - for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++) - { - textKeyChain[i] -= encryptedTextKeyChain[i]; - } - - //LOAD returningText - for (int i = 0; i < sizeof(textKeyChain) / sizeof(int); i++) - { - returningText[i] = (char) textKeyChain[i]; - } - - return returningText; -} diff --git a/src/encrypter.c b/src/encrypter.c deleted file mode 100644 index f2cfd52..0000000 --- a/src/encrypter.c +++ /dev/null @@ -1,123 +0,0 @@ -#include "../include/encrypter.h" - -#include -#include -#include -#include -#include - -#include "../include/flags.h" - -char* -encryptText(char *text, char *keyNew) -{ - srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM" - - //VARIABLES - char *key = malloc(KEY_LENGTH); - char *returningText; - char *textBuffer; - int textKeyChain[strlen(text)]; - int numberBuffer; - - if (keyNew != NULL) - { - if (strlen(keyNew) != KEY_LENGTH) - { - fprintf(stderr, "Key must be 50 characters long!\n"); - exit(INVALID_KEY); - } - - strcpy(key, keyNew); - - goto skipKey; - } - - //LOAD KEY - for (int i = 0; i < KEY_LENGTH; i++) - { - //SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52 - numberBuffer = (rand() % 52) + 1; - - //GET CHAR FROM numberBuffer - if (numberBuffer > 26) - { - numberBuffer += 70; - } else - { - numberBuffer += 64; - } - - key[i] = (char) numberBuffer; - } - - printf("Your key is: %s\n!!! SAVE IT SOMEWHERE !!!\n\n", key); - - skipKey: - - //LOAD textKeyChain - for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++) - { - numberBuffer = i; - - //CHECK, IF numberBuffer ISN'T GREATER THAN KEY_LENGTH AND CUT UNUSED LENGTH - while (numberBuffer >= KEY_LENGTH) - { - numberBuffer -= KEY_LENGTH; - } - - //FILL textKeyChain - if ((numberBuffer + 1) % 3 == 0) - { - textKeyChain[i] = key[numberBuffer] * key[numberBuffer + 1]; - } else if ((numberBuffer + 1) % 2 == 0) - { - textKeyChain[i] = key[numberBuffer] - key[numberBuffer + 1]; - } else - { - textKeyChain[i] = key[numberBuffer] + key[numberBuffer + 1]; - } - } - - //ACTUALLY ENCRYPT TEXT - for (int i = 0; i < strlen(text); i++) - { - textKeyChain[i] -= (int) text[i]; - } - - numberBuffer = 0; - - //COUNT REQUIRED SIZE FOR returningText - for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++) - { - numberBuffer += floor(log10(abs(textKeyChain[i]))) + 1; - - //CHECK FOR MINUS - if (textKeyChain[i] > 0) numberBuffer++; - } - - //ALLOCATE returningText (WITH THE SEPARATORS) - returningText = malloc(numberBuffer + (sizeof(textKeyChain) / sizeof(int) - 1)); - - //LOAD returningText - for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++) - { - textBuffer = malloc(floor(log10(abs(textKeyChain[i])))); - - sprintf(textBuffer, "%d", textKeyChain[i]); - - strcat(returningText, textBuffer); - - if (i != (sizeof(textKeyChain) / sizeof(int) - 1)) - { - strcat(returningText, ENCRYPTION_SEPARATOR_STRING); - } - - free(textBuffer); - } - - //DEALLOCATION - free(key); - - return returningText; -} \ No newline at end of file diff --git a/src/test/main.c b/src/test/main.c deleted file mode 100644 index cfe3ee6..0000000 --- a/src/test/main.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#include "../../include/encrypter.h" -#include "../../include/decrypter.h" - -int -main(int args, char *argv[]) -{ - char *text = encryptText("Pepa smrdí.", "dsadhagsdhuhasvbdzgavdgasvgzduasvgzdavdhbashudbuas"); - printf("%s\n", text); - - text = decryptText(text, "dsadhagsdhuhasvbdzgavdgasvgzduasvgzdavdhbashudbuas"); - printf("%s\n", text); - - free(text); - return 0; -} \ No newline at end of file