renamed every global function & flag

basically - it's in snake_case now AND there's "why2_" at the beginning
This commit is contained in:
Václav Šmejkal 2023-01-29 20:14:11 +01:00
parent da25700f11
commit 5e8cf54145
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
17 changed files with 255 additions and 255 deletions

View File

@ -21,6 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
outputFlags decryptText(char *text, char *keyNew); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED why2_output_flags why2_decrypt_text(char *text, char *keyNew); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
#endif #endif

View File

@ -21,6 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
outputFlags encryptText(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED why2_output_flags why2_encrypt_text(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED
#endif #endif

View File

@ -20,70 +20,70 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define WHY2_FLAGS_H #define WHY2_FLAGS_H
//CONSTS //CONSTS
const enum EXIT_CODES //exit codes you fucking idiot const enum WHY2_EXIT_CODES //exit codes you fucking idiot
{ {
SUCCESS = 0, //EXIT CODE FOR SUCCESSFUL RUN WHY2_SUCCESS = 0, //EXIT CODE FOR WHY2_SUCCESSFUL RUN
INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY WHY2_INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY
INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT WHY2_INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT
DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED WHY2_DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED
UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED WHY2_WHY2_UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED
}; };
#define VERSION "v4.3.2" //VERSION OF CURRENT BUILD > DO NOT TOUCH THIS < #define WHY2_VERSION "v4.3.2" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS <
#define VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json #define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json
#define VERSIONS_NAME "/tmp/why2-versions.json" //do I have to explain this? #define WHY2_VERSIONS_NAME "/tmp/why2-versions.json" //do I have to explain this?
#define UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY) #define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY)
#define UPDATE_NAME "/tmp/why2-update" // fuck you #define WHY2_UPDATE_NAME "/tmp/why2-update" // fuck you
#define UPDATE_COMMAND "tmux new-session -d \"cd {DIR} && make install\"" #define WHY2_UPDATE_COMMAND "tmux new-session -d \"cd {DIR} && make install\""
#define TEST_TEXT "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" //TEST TEXT FOR ENCRYPTION IN why2-test BINARY #define WHY2_TEST_TEXT "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" //TEST TEXT FOR ENCRYPTION IN why2-test BINARY
#define TEXT_TO_ENCRYPT "Some text yk" //THIS TEXT WILL BE ENCRYPTED IN why2-app BINARY #define WHY2_TEXT_TO_ENCRYPT "Some text yk" //THIS TEXT WILL BE ENCRYPTED IN why2-app BINARY
#define CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN #define WHY2_CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN
#define CURL_TIMEOUT 3 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya #define WHY2_CURL_TIMEOUT 3 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya
#define NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json #define WHY2_NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json
#define DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS VERSIONS_NAME'S #define WHY2_DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS WHY2_VERSIONS_NAME'S
#define UNUSED __attribute__((unused)) //SAME COMMENT AS DEPRECATED'S #define WHY2_UNUSED __attribute__((unused)) //SAME COMMENT AS WHY2_DEPRECATED'S
//TYPES //TYPES
typedef char why2_bool; //READ THE NAME OR I WILL FIND YOU AND FUCK YOUR MOTHERFUCKING DOG!!! typedef char why2_bool; //READ THE NAME OR I WILL FIND YOU AND FUCK YOUR MOTHERFUCKING DOG!!!
typedef int (*encryptionOperation_type_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK typedef int (*why2_encryption_operation_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK
typedef struct typedef struct
{ {
why2_bool noCheck; //BOOLEAN FOR SKIPPING VERSION CHECK why2_bool noCheck; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK
why2_bool noOutput; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING why2_bool why2_no_output; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING
why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY VERSION IF OLD IS USED why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED
} inputFlags; } why2_input_flags;
typedef struct typedef struct
{ {
char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT
char *usedKey; //VARIABLE FOR USED/GENERATED KEY char *usedKey; //VARIABLE FOR USED/GENERATED KEY
unsigned long unusedKeySize; //VARIABLE FOR COUNT OF UNUSED CHARACTERS IN KEY unsigned long unusedKeySize; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY
unsigned long repeatedKeySize; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unusedKeySize) unsigned long repeatedKeySize; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unusedKeySize)
unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs
enum EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE enum WHY2_EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE
} outputFlags; } why2_output_flags;
//NOTE: Variables were moved to 'flags.c' to force y'all using getters //NOTE: Variables were moved to 'flags.c' to force y'all using getters
//GETTERS //GETTERS
char getEncryptionSeparator(void); char why2_get_encryption_separator(void);
unsigned long getKeyLength(void); unsigned long why2_get_key_length(void);
inputFlags getDefaultFlags(void); //THIS GENERATES inputFlags WITH DEFAULT VALUES why2_input_flags why2_get_default_flags(void); //THIS GENERATES why2_input_flags WITH DEFAULT VALUES
inputFlags getFlags(void); //RETURNS USED FLAGS why2_input_flags why2_get_flags(void); //RETURNS USED FLAGS
outputFlags noOutput(enum EXIT_CODES exitCode); //SAME AS getDefaultFlags() BUT FOR outputFlags why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags
encryptionOperation_type_cb getEncryptionOperation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION why2_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION
why2_bool getFlagsChanged(void); why2_bool why2_get_flags_changed(void);
//SETTERS //SETTERS
void setEncryptionSeparator(char encryptionSeparatorNew); void why2_set_encryption_separator(char encryptionSeparatorNew);
void setKeyLength(int keyLengthNew); void why2_set_key_length(int keyLengthNew);
void setFlags(inputFlags newFlags); //.... whatcha think? void why2_set_flags(why2_input_flags newFlags); //.... whatcha think?
void setEncryptionOperation(encryptionOperation_type_cb newEncryptionOperation); //are you that dumb? void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation); //are you that dumb?
#endif #endif

View File

@ -20,53 +20,53 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define WHY2_LOGGER_FLAGS_H #define WHY2_LOGGER_FLAGS_H
//CONSTS //CONSTS
const enum LOGGER_EXIT_CODES //exit codes you fucking idiot (2#) const enum LOGGER_WHY2_EXIT_CODES //exit codes you fucking idiot (2#)
{ {
INVALID_FILE = -1 //THIS WILL HAPPEN IF YOU USE TOO MUCH LOGS lol INVALID_FILE = -1 //THIS WILL HAPPEN IF YOU USE TOO MUCH LOGS lol
}; };
#define WRITE_MESSAGE_1 "Hello from logger-test! 👋" #define WHY2_WRITE_MESSAGE_1 "Hello from logger-test! 👋"
#define WRITE_MESSAGE_2 "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" #define WHY2_WRITE_MESSAGE_2 "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿"
#define WRITE_MESSAGE_3 "ˢᵃʸ ʸᵉˢ ᵗᵒ ᵈʳᵘᵍˢ" #define WHY2_WRITE_MESSAGE_3 "ˢᵃʸ ʸᵉˢ ᵗᵒ ᵈʳᵘᵍˢ"
#define WRITE_DIR "./logs" #define WHY2_WRITE_DIR "./logs"
#define LOG_LATEST "latest.log" #define WHY2_LOG_LATEST "latest.log"
#define LOG_FORMAT "yyyy-mm-dd_xxx.log" //THE LAST xxx IS FOR BASE-16 NUMBER OF USAGE THAT DAY (SO MAX IS 4095 [FFF] USAGES PER DAY) #define WHY2_LOG_FORMAT "yyyy-mm-dd_xxx.log" //THE LAST xxx IS FOR BASE-16 NUMBER OF USAGE THAT DAY (SO MAX IS 4095 [FFF] USAGES PER DAY)
#define LOG_FORMAT_START "yyyy-mm-dd" //FIRST PART OF LOG_FORMAT #define WHY2_LOG_FORMAT_START "yyyy-mm-dd" //FIRST PART OF WHY2_LOG_FORMAT
#define LOG_FORMATTING "%s/%s_%03x.log" //SAME THING AS LOG_FORMAT, BUT USED IN sprintf IN logger.c, NOT AS LENGTH #define WHY2_LOG_FORMATTING "%s/%s_%03x.log" //SAME THING AS WHY2_LOG_FORMAT, BUT USED IN sprintf IN logger.c, NOT AS LENGTH
#define LOG_FORMATTING_START "%04d-%02d-%02d" //FIRST PART OF LOG_FORMATTING #define WHY2_LOG_FORMATTING_START "%04d-%02d-%02d" //FIRST PART OF WHY2_LOG_FORMATTING
#define WRITE_FORMAT "[hh:mm:ss]: " //LOG MESSAGE'S PREFIX (THE SPACE AT THE END IS INTENTIONAL) #define WHY2_WRITE_FORMAT "[hh:mm:ss]: " //LOG MESSAGE'S PREFIX (THE SPACE AT THE END IS INTENTIONAL)
#define WRITE_FORMATTING "[%02d:%02d:%02d]: %s\n" //guess what #define WHY2_WRITE_FORMATTING "[%02d:%02d:%02d]: %s\n" //guess what
#define LOG_LATEST_FORMATTING "%s/%s" #define WHY2_LOG_LATEST_FORMATTING "%s/%s"
#define MAX_USAGE 0xfff //LOOK AT LOG_FORMAT #define WHY2_MAX_USAGE 0xfff //LOOK AT WHY2_LOG_FORMAT
//TYPES //TYPES
typedef struct typedef struct
{ {
int file; int file;
char *fileName; char *fileName;
} logFile; } why2_log_file;
typedef struct typedef struct
{ {
char *key; char *key;
} logFlags; } why2_log_flags;
typedef struct typedef struct
{ {
char **decryptedText; char **decryptedText;
unsigned long length; unsigned long length;
} decryptedOutput; } why2_decrypted_output;
//GETTERS //GETTERS
logFlags getLogFlags(void); why2_log_flags why2_get_log_flags(void);
//SETTERS //SETTERS
void setLogFlags(logFlags logFlagsNew); void why2_set_log_flags(why2_log_flags why2_log_flagsNew);
#endif #endif

View File

@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/flags.h> #include <why2/logger/flags.h>
logFile initLogger(char *directoryPath); //CREATES LOGGING FILE IN directoryPath why2_log_file why2_init_logger(char *directoryPath); //CREATES LOGGING FILE IN directoryPath
void writeLog(int loggerFile, char *logMessage); //WRITES logMessage TO loggerFile void why2_write_log(int loggerFile, char *logMessage); //WRITES logMessage TO loggerFile
#endif #endif

View File

@ -21,8 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/flags.h> #include <why2/logger/flags.h>
void deallocateLogger(logFile logger); //USE THIS IF YOU WANT TO DEALLOCATE FILE POINTER RETURNED BY logger'S initLogger void why2_deallocate_logger(why2_log_file logger); //USE THIS IF YOU WANT TO DEALLOCATE FILE POINTER RETURNED BY logger'S why2_init_logger
void deallocateDecryptedOutput(decryptedOutput output); //DEALLOCATION OF POINTER-TO-POINTER, WHY TF ARE YOU READING THIS void why2_deallocate_decrypted_output(why2_decrypted_output output); //DEALLOCATION OF POINTER-TO-POINTER, WHY TF ARE YOU READING THIS
decryptedOutput decryptLogger(logFile logger); //PASS logger AND FLAGS, AND PROGRAM WILL DECRYPT YOUR LOG... WHAT DID YOU EXPECT? why2_decrypted_output why2_decrypt_logger(why2_log_file logger); //PASS logger AND FLAGS, AND PROGRAM WILL DECRYPT YOUR LOG... WHAT DID YOU EXPECT?
#endif #endif

View File

@ -23,15 +23,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
void generateKey(char *key, int keyLength); //GENERATE ENCRYPTION KEY void why2_generate_key(char *key, int keyLength); //GENERATE ENCRYPTION KEY
void deallocateOutput(outputFlags flags); //DEALLOCATES flags void why2_deallocate_output(why2_output_flags flags); //DEALLOCATES flags
enum EXIT_CODES checkVersion(void); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED enum WHY2_EXIT_CODES why2_check_version(void); //THIS FUNCTION CHECKS IF LATEST WHY2_VERSION OF WHY2 IS USED
enum EXIT_CODES checkKey(char *key); //CHECKS IF KEY IS VALID enum WHY2_EXIT_CODES why2_check_key(char *key); //CHECKS IF KEY IS VALID
enum EXIT_CODES checkText(char *text); //CHECKS IF TEXT IS VALID enum WHY2_EXIT_CODES why2_check_text(char *text); //CHECKS IF TEXT IS VALID
unsigned long countIntLength(int number); //RETURNS LENGTH OF number unsigned long why2_count_int_length(int number); //RETURNS LENGTH OF number
unsigned long countUnusedKeySize(char *text, char *key); //COUNT unusedKeySize unsigned long why2_count_unused_key_size(char *text, char *key); //COUNT unusedKeySize
unsigned long countRepeatedKeySize(char *text, char *key); //COUNT repeatedKeySize unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeatedKeySize
unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS
#endif #endif

View File

@ -23,10 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void) int main(void)
{ {
//SET FLAGS //SET FLAGS
setFlags((inputFlags) {1, 1, 0}); why2_set_flags((why2_input_flags) {1, 1, 0});
//RUN ENCRYPTION WITH TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE VERSION & PREVENT ANY OUTPUT //RUN ENCRYPTION WITH WHY2_TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE WHY2_VERSION & PREVENT ANY OUTPUT
outputFlags encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL); why2_output_flags encryptedText = why2_encrypt_text(WHY2_TEXT_TO_ENCRYPT, NULL);
//SIMPLE TEXT //SIMPLE TEXT
printf printf
@ -39,11 +39,11 @@ int main(void)
"If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \b\n" "If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \b\n"
"Thank you so much for supporting this project!\n" "Thank you so much for supporting this project!\n"
, TEXT_TO_ENCRYPT, encryptedText.outputText , WHY2_TEXT_TO_ENCRYPT, encryptedText.outputText
); );
//DEALLOCATION //DEALLOCATION
deallocateOutput(encryptedText); why2_deallocate_output(encryptedText);
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
#include <why2/misc.h> #include <why2/misc.h>
outputFlags decryptText(char *text, char *keyNew) why2_output_flags why2_decrypt_text(char *text, char *keyNew)
{ {
//CHECK VARIABLE //CHECK VARIABLE
unsigned char checkExitCode; unsigned char checkExitCode;
@ -36,26 +36,26 @@ outputFlags decryptText(char *text, char *keyNew)
struct timeval finishTime; struct timeval finishTime;
gettimeofday(&startTime, NULL); gettimeofday(&startTime, NULL);
//CHECK FOR ACTIVE VERSION //CHECK FOR ACTIVE WHY2_VERSION
if ((checkExitCode = checkVersion()) != SUCCESS) if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
//CHECK FOR INVALID text //CHECK FOR INVALID text
if ((checkExitCode = checkText(text)) != SUCCESS) if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
//CHECK FOR INVALID key //CHECK FOR INVALID key
if ((checkExitCode = checkKey(keyNew)) != SUCCESS) if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
//REDEFINE keyLength //REDEFINE keyLength
setKeyLength(strlen(keyNew)); why2_set_key_length(strlen(keyNew));
//VARIABLES //VARIABLES
char *returningText; char *returningText;
@ -71,7 +71,7 @@ outputFlags decryptText(char *text, char *keyNew)
//GET LENGTH OF returningText AND textKeyChain //GET LENGTH OF returningText AND textKeyChain
for (int i = 0; i < (int) strlen(usedText); i++) for (int i = 0; i < (int) strlen(usedText); i++)
{ {
if (usedText[i] == getEncryptionSeparator()) numberBuffer++; if (usedText[i] == why2_get_encryption_separator()) numberBuffer++;
} }
//SET LENGTH (numberBuffer) //SET LENGTH (numberBuffer)
@ -81,7 +81,7 @@ outputFlags decryptText(char *text, char *keyNew)
textKeyChainLength = numberBuffer; textKeyChainLength = numberBuffer;
//LOAD textKeyChain //LOAD textKeyChain
generateTextKeyChain(key, textKeyChain, numberBuffer); why2_generate_text_key_chain(key, textKeyChain, numberBuffer);
//LOAD encryptedTextKeyChain //LOAD encryptedTextKeyChain
for (int i = 0; i < textKeyChainLength; i++) for (int i = 0; i < textKeyChainLength; i++)
@ -91,7 +91,7 @@ outputFlags decryptText(char *text, char *keyNew)
//GET LENGTH OF EACH CHARACTER //GET LENGTH OF EACH CHARACTER
for (int j = 0; j < (int) strlen(usedText); j++) for (int j = 0; j < (int) strlen(usedText); j++)
{ {
if (usedText[j] == getEncryptionSeparator()) break; if (usedText[j] == why2_get_encryption_separator()) break;
numberBuffer++; numberBuffer++;
} }
@ -121,7 +121,7 @@ outputFlags decryptText(char *text, char *keyNew)
//DECRYPT TEXT //DECRYPT TEXT
for (int i = 0; i < textKeyChainLength; i++) for (int i = 0; i < textKeyChainLength; i++)
{ {
textKeyChain[i] = getEncryptionOperation()(textKeyChain[i], encryptedTextKeyChain[i]); textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], encryptedTextKeyChain[i]);
} }
//LOAD returningText //LOAD returningText
@ -134,14 +134,14 @@ outputFlags decryptText(char *text, char *keyNew)
gettimeofday(&finishTime, NULL); gettimeofday(&finishTime, NULL);
//LOAD output //LOAD output
outputFlags output = why2_output_flags output =
{ {
returningText, //DECRYPTED TEXT returningText, //DECRYPTED TEXT
key, //USED KEY key, //USED KEY
countUnusedKeySize(returningText, key), // NUMBER OF UNUSED CHARS IN KEY why2_count_unused_key_size(returningText, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY
countRepeatedKeySize(returningText, key), //NUMBER OF REPEATED CHARS IN KEY why2_count_repeated_key_size(returningText, key), //NUMBER OF REPEATED CHARS IN KEY
compareTimeMicro(startTime, finishTime), // ELAPSED TIME why2_compare_time_micro(startTime, finishTime), // ELAPSED TIME
SUCCESS //EXIT CODE WHY2_SUCCESS //EXIT CODE
}; };
//DEALLOCATION //DEALLOCATION

View File

@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h> #include <why2/flags.h>
#include <why2/misc.h> #include <why2/misc.h>
outputFlags encryptText(char *text, char *keyNew) why2_output_flags why2_encrypt_text(char *text, char *keyNew)
{ {
//CHECK VARIABLE //CHECK VARIABLE
unsigned char checkExitCode; unsigned char checkExitCode;
@ -36,16 +36,16 @@ outputFlags encryptText(char *text, char *keyNew)
struct timeval finishTime; struct timeval finishTime;
gettimeofday(&startTime, NULL); gettimeofday(&startTime, NULL);
//CHECK FOR ACTIVE VERSION //CHECK FOR ACTIVE WHY2_VERSION
if ((checkExitCode = checkVersion()) != SUCCESS) if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
//CHECK FOR INVALID text //CHECK FOR INVALID text
if ((checkExitCode = checkText(text)) != SUCCESS) if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
//VARIABLES //VARIABLES
@ -58,35 +58,35 @@ outputFlags encryptText(char *text, char *keyNew)
if (keyNew != NULL) if (keyNew != NULL)
{ {
//CHECK FOR INVALID key //CHECK FOR INVALID key
if ((checkExitCode = checkKey(keyNew)) != SUCCESS) if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS)
{ {
return noOutput(checkExitCode); return why2_no_output(checkExitCode);
} }
key = strdup(keyNew); key = strdup(keyNew);
//REDEFINE keyLength //REDEFINE keyLength
setKeyLength(strlen(key)); why2_set_key_length(strlen(key));
} else //LOAD KEY } else //LOAD KEY
{ {
key = malloc(getKeyLength() + 1); key = malloc(why2_get_key_length() + 1);
generateKey(key, getKeyLength()); why2_generate_key(key, why2_get_key_length());
} }
//LOAD textKeyChain //LOAD textKeyChain
generateTextKeyChain(key, textKeyChain, strlen(text)); why2_generate_text_key_chain(key, textKeyChain, strlen(text));
//ACTUALLY ENCRYPT TEXT //ACTUALLY ENCRYPT TEXT
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text); i++)
{ {
textKeyChain[i] = getEncryptionOperation()(textKeyChain[i], (int) text[i]); textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], (int) text[i]);
} }
//COUNT REQUIRED SIZE FOR returningText //COUNT REQUIRED SIZE FOR returningText
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text); i++)
{ {
numberBuffer += countIntLength(textKeyChain[i]); numberBuffer += why2_count_int_length(textKeyChain[i]);
} }
//ALLOCATE returningText (WITH THE SEPARATORS) //ALLOCATE returningText (WITH THE SEPARATORS)
@ -95,7 +95,7 @@ outputFlags encryptText(char *text, char *keyNew)
//LOAD returningText //LOAD returningText
for (int i = 0; i < (int) strlen(text); i++) for (int i = 0; i < (int) strlen(text); i++)
{ {
numberBuffer = sizeof(int) * countIntLength(textKeyChain[i]); numberBuffer = sizeof(int) * why2_count_int_length(textKeyChain[i]);
textBuffer = realloc(textBuffer, numberBuffer); textBuffer = realloc(textBuffer, numberBuffer);
@ -106,7 +106,7 @@ outputFlags encryptText(char *text, char *keyNew)
if (i != (int) strlen(text) - 1) if (i != (int) strlen(text) - 1)
{ {
textBuffer = realloc(textBuffer, 2); textBuffer = realloc(textBuffer, 2);
sprintf(textBuffer, "%c", getEncryptionSeparator()); sprintf(textBuffer, "%c", why2_get_encryption_separator());
strcat(returningText, textBuffer); strcat(returningText, textBuffer);
} }
@ -116,14 +116,14 @@ outputFlags encryptText(char *text, char *keyNew)
gettimeofday(&finishTime, NULL); gettimeofday(&finishTime, NULL);
//LOAD output //LOAD output
outputFlags output = why2_output_flags output =
{ {
returningText, //ENCRYPTED TEXT returningText, //ENCRYPTED TEXT
key, //GENERATED/USED KEY key, //GENERATED/USED KEY
countUnusedKeySize(text, key), // NUMBER OF UNUSED CHARS IN KEY why2_count_unused_key_size(text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY
countRepeatedKeySize(text, key), //NUMBER OF REPEATED CHARS IN KEY why2_count_repeated_key_size(text, key), //NUMBER OF REPEATED CHARS IN KEY
compareTimeMicro(startTime, finishTime), // ELAPSED TIME why2_compare_time_micro(startTime, finishTime), // ELAPSED TIME
SUCCESS //EXIT CODE WHY2_SUCCESS //EXIT CODE
}; };
//DEALLOCATION //DEALLOCATION

View File

@ -21,86 +21,86 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
//CONSTS (this is just local) //CONSTS (this is just local)
#define DEFAULT_FLAGS (inputFlags) { 0, 0, 0 } #define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0 }
int encryptionOperation(int text, int encryptedText); int encryptionOperation(int text, int encryptedText);
//VARIABLES //VARIABLES
char encryptionSeparator = '.'; //NOPE > DO NOT TOUCH THIS, USE setEncryptionSeparator instead < char encryptionSeparator = '.'; //NOPE > DO NOT TOUCH THIS, USE why2_set_encryption_separator instead <
unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE setKeyLength instead < unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE why2_set_key_length instead <
inputFlags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS why2_input_flags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS
encryptionOperation_type_cb encryptionOperation_cb = encryptionOperation; why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation;
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE setFlags why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
//GETTERS //GETTERS
char getEncryptionSeparator(void) char why2_get_encryption_separator(void)
{ {
return encryptionSeparator; return encryptionSeparator;
} }
unsigned long getKeyLength(void) unsigned long why2_get_key_length(void)
{ {
return keyLength; return keyLength;
} }
inputFlags getDefaultFlags(void) why2_input_flags why2_get_default_flags(void)
{ {
return DEFAULT_FLAGS; return DEFAULT_FLAGS;
} }
inputFlags getFlags(void) why2_input_flags why2_get_flags(void)
{ {
return flagsAllah; return flagsAllah;
} }
outputFlags noOutput(enum EXIT_CODES exitCode) why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode)
{ {
char *emptyText = malloc(1); //TEXT char *emptyText = malloc(1); //TEXT
emptyText[0] = '\0'; emptyText[0] = '\0';
char *emptyKey = malloc(getKeyLength() + 1); //KEY char *emptyKey = malloc(why2_get_key_length() + 1); //KEY
for (int i = 0; i < (int) getKeyLength(); i++) for (int i = 0; i < (int) why2_get_key_length(); i++)
{ {
emptyKey[i] = 'x'; emptyKey[i] = 'x';
} }
emptyKey[getKeyLength()] = '\0'; emptyKey[why2_get_key_length()] = '\0';
return (outputFlags) { emptyText, emptyKey, 0, 0, 0, exitCode }; return (why2_output_flags) { emptyText, emptyKey, 0, 0, 0, exitCode };
} }
encryptionOperation_type_cb getEncryptionOperation(void) why2_encryption_operation_cb why2_get_encryption_operation(void)
{ {
return encryptionOperation_cb; return encryptionOperation_cb;
} }
why2_bool getFlagsChanged(void) why2_bool why2_get_flags_changed(void)
{ {
return flagsChanged; return flagsChanged;
} }
//SETTERS //SETTERS
void setEncryptionSeparator(char encryptionSeparatorNew) void why2_set_encryption_separator(char encryptionSeparatorNew)
{ {
if (encryptionSeparatorNew <= 31) return; if (encryptionSeparatorNew <= 31) return;
encryptionSeparator = encryptionSeparatorNew; encryptionSeparator = encryptionSeparatorNew;
} }
void setKeyLength(int keyLengthNew) void why2_set_key_length(int keyLengthNew)
{ {
if (keyLengthNew < 1) return; if (keyLengthNew < 1) return;
keyLength = keyLengthNew; keyLength = keyLengthNew;
} }
void setFlags(inputFlags newFlags) void why2_set_flags(why2_input_flags newFlags)
{ {
flagsAllah = newFlags; flagsAllah = newFlags;
if (!flagsChanged) flagsChanged = 1; if (!flagsChanged) flagsChanged = 1;
} }
void setEncryptionOperation(encryptionOperation_type_cb newEncryptionOperation) void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation)
{ {
encryptionOperation_cb = newEncryptionOperation; encryptionOperation_cb = newEncryptionOperation;
} }

View File

@ -39,7 +39,7 @@ int main(void)
FILE *outputStreamBuffer = stdout; FILE *outputStreamBuffer = stdout;
//FLAGS //FLAGS
inputFlags flags = why2_input_flags flags =
{ {
0, //SKIP CHECK 0, //SKIP CHECK
0, //NO OUTPUT 0, //NO OUTPUT
@ -47,37 +47,37 @@ int main(void)
}; };
//SET FLAGS //SET FLAGS
setFlags(flags); why2_set_flags(flags);
//SET KEY_LENGTH TO 100 //SET KEY_LENGTH TO 100
setKeyLength(100); why2_set_key_length(100);
//SET ENCRYPTION_SEPARATOR TO '|' //SET ENCRYPTION_SEPARATOR TO '|'
setEncryptionSeparator('|'); why2_set_encryption_separator('|');
//SET outputBuffer to NULL //SET outputBuffer to NULL
outputBuffer[0] = '\0'; outputBuffer[0] = '\0';
//SET encryptionOperation to encryptionOperationTest //SET encryptionOperation to encryptionOperationTest
setEncryptionOperation(encryptionOperationTest); why2_set_encryption_operation(encryptionOperationTest);
//ENCRYPT //ENCRYPT
outputFlags encrypted = encryptText(TEST_TEXT, NULL); why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL);
textBuffer = strdup(encrypted.outputText); //GET ENCRYPTED TEXT textBuffer = strdup(encrypted.outputText); //GET ENCRYPTED TEXT
keyBuffer = strdup(encrypted.usedKey); //GET KEY keyBuffer = strdup(encrypted.usedKey); //GET KEY
timeBuffer = encrypted.elapsedTime; //GET TIME 1 timeBuffer = encrypted.elapsedTime; //GET TIME 1
//DEALLOCATE BUFFER //DEALLOCATE BUFFER
deallocateOutput(encrypted); why2_deallocate_output(encrypted);
//DECRYPT //DECRYPT
encrypted = decryptText(textBuffer, keyBuffer); encrypted = why2_decrypt_text(textBuffer, keyBuffer);
timeBuffer += encrypted.elapsedTime; //GET TIME 1 timeBuffer += encrypted.elapsedTime; //GET TIME 1
//COMPARE DIFFERENCE //COMPARE DIFFERENCE
if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) //SUCCESS if (strcmp(encrypted.outputText, WHY2_TEST_TEXT) == 0 && encrypted.exitCode == 0) //WHY2_SUCCESS
{ {
statusBuffer = strdup("successful"); statusBuffer = strdup("successful");
} }
@ -107,7 +107,7 @@ int main(void)
"REPEATED KEY: \t\"%lu\"\n" "REPEATED KEY: \t\"%lu\"\n"
"EXIT CODE: \t\"%d\"\n" "EXIT CODE: \t\"%d\"\n"
, statusBuffer, TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.repeatedKeySize, encrypted.exitCode , statusBuffer, WHY2_TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.repeatedKeySize, encrypted.exitCode
); );
//DEALLOCATION //DEALLOCATION
@ -115,7 +115,7 @@ int main(void)
free(keyBuffer); free(keyBuffer);
free(statusBuffer); free(statusBuffer);
free(outputBuffer); free(outputBuffer);
deallocateOutput(encrypted); why2_deallocate_output(encrypted);
return exitCode; return exitCode;
} }

View File

@ -37,7 +37,7 @@ double multiply_cb(int a, int b) { return a * b; }
double subtract_cb(int a, int b) { return a - b; } double subtract_cb(int a, int b) { return a - b; }
double sum_cb(int a, int b) { return a + b; } double sum_cb(int a, int b) { return a + b; }
int unlink_cb(const char *fpath, UNUSED const struct stat *sb, UNUSED int typeflag, UNUSED struct FTW *ftwbuf) int unlink_cb(const char *fpath, WHY2_UNUSED const struct stat *sb, WHY2_UNUSED int typeflag, WHY2_UNUSED struct FTW *ftwbuf)
{ {
int rv = remove(fpath); int rv = remove(fpath);
@ -87,21 +87,21 @@ char *replaceWord(char *string, char *old, char *new) //CODE FROM: https://www.g
return result; return result;
} }
enum EXIT_CODES checkVersion(void) enum WHY2_EXIT_CODES why2_check_version(void)
{ {
if (getFlags().noCheck) return SUCCESS; if (why2_get_flags().noCheck) return WHY2_SUCCESS;
//FILE-CHECK VARIABLES //FILE-CHECK VARIABLES
int notFoundBuffer = 0; int notFoundBuffer = 0;
//CURL VARIABLES //CURL VARIABLES
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
FILE *fileBuffer = fopen(VERSIONS_NAME, "w+"); FILE *fileBuffer = fopen(WHY2_VERSIONS_NAME, "w+");
//GET versions.json //GET versions.json
curl_easy_setopt(curl, CURLOPT_URL, VERSIONS_URL); curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fileBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fileBuffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT); curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
//DOWNLOAD versions.json //DOWNLOAD versions.json
curl_easy_perform(curl); curl_easy_perform(curl);
@ -110,17 +110,17 @@ enum EXIT_CODES checkVersion(void)
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
fclose(fileBuffer); fclose(fileBuffer);
while (access(VERSIONS_NAME, R_OK) != 0) while (access(WHY2_VERSIONS_NAME, R_OK) != 0)
{ {
notFoundBuffer++; notFoundBuffer++;
if (notFoundBuffer == NOT_FOUND_TRIES) if (notFoundBuffer == WHY2_NOT_FOUND_TRIES)
{ {
if (!getFlags().noOutput) fprintf(stderr, "%s'%s' not found! Exiting...\n", CLEAR_SCREEN, VERSIONS_NAME); if (!why2_get_flags().why2_no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME);
return DOWNLOAD_FAILED; return WHY2_DOWNLOAD_FAILED;
} }
if (!getFlags().noOutput) printf("%s'%s' not found (%dx)! Trying again in a second.\n", CLEAR_SCREEN, VERSIONS_NAME, notFoundBuffer); if (!why2_get_flags().why2_no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, notFoundBuffer);
sleep(1); sleep(1);
} }
@ -131,7 +131,7 @@ enum EXIT_CODES checkVersion(void)
int bufferSize; int bufferSize;
//COUNT LENGTH OF buffer AND STORE IT IN bufferSize //COUNT LENGTH OF buffer AND STORE IT IN bufferSize
fileBuffer = fopen(VERSIONS_NAME, "r"); fileBuffer = fopen(WHY2_VERSIONS_NAME, "r");
fseek(fileBuffer, 0, SEEK_END); fseek(fileBuffer, 0, SEEK_END);
bufferSize = ftell(fileBuffer); bufferSize = ftell(fileBuffer);
rewind(fileBuffer); //REWIND fileBuffer (NO SHIT) rewind(fileBuffer); //REWIND fileBuffer (NO SHIT)
@ -147,14 +147,14 @@ enum EXIT_CODES checkVersion(void)
//CHECK FOR TEXT IN buffer //CHECK FOR TEXT IN buffer
if (strcmp(buffer, "") == 0) if (strcmp(buffer, "") == 0)
{ {
if (!getFlags().noOutput) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n"); if (!why2_get_flags().why2_no_output) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n");
//WAIT FOR 5 SECONDS //WAIT FOR 5 SECONDS
sleep(5); sleep(5);
free(buffer); free(buffer);
fclose(fileBuffer); fclose(fileBuffer);
return SUCCESS; return WHY2_SUCCESS;
} }
//CLEANUP //CLEANUP
@ -164,16 +164,16 @@ enum EXIT_CODES checkVersion(void)
parsedJson = json_tokener_parse(buffer); //yes, ik, i could use json_object_from_file, but I need to check for internet somehow parsedJson = json_tokener_parse(buffer); //yes, ik, i could use json_object_from_file, but I need to check for internet somehow
json_object_object_get_ex(parsedJson, "active", &active); json_object_object_get_ex(parsedJson, "active", &active);
if (strcmp(VERSION, json_object_get_string(active)) != 0) if (strcmp(WHY2_VERSION, json_object_get_string(active)) != 0)
{ {
//UPDATE //UPDATE
if (getFlags().update) if (why2_get_flags().update)
{ {
//CHECK FOR ROOT PERMISSIONS //CHECK FOR ROOT PERMISSIONS
if (getuid() != 0) if (getuid() != 0)
{ {
if (!getFlags().noOutput) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); if (!why2_get_flags().why2_no_output) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n");
return UPDATE_FAILED; return WHY2_WHY2_UPDATE_FAILED;
} }
//VARIABLES //VARIABLES
@ -183,48 +183,48 @@ enum EXIT_CODES checkVersion(void)
int installCode; int installCode;
//MESSAGE //MESSAGE
if (!getFlags().noOutput) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n"); if (!why2_get_flags().why2_no_output) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n");
//CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'UPDATE_NAME' //CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'WHY2_UPDATE_NAME'
if (access(UPDATE_NAME, F_OK) == 0) if (access(WHY2_UPDATE_NAME, F_OK) == 0)
{ {
removeDirectory(UPDATE_NAME); removeDirectory(WHY2_UPDATE_NAME);
} }
git_libgit2_init(); //START GIT2 git_libgit2_init(); //START GIT2
exitCode = git_clone(&repo, UPDATE_URL, UPDATE_NAME, NULL); //CLONE exitCode = git_clone(&repo, WHY2_UPDATE_URL, WHY2_UPDATE_NAME, NULL); //CLONE
git_libgit2_shutdown(); //STOP GIT2 git_libgit2_shutdown(); //STOP GIT2
//CHECK FOR ERRORS //CHECK FOR ERRORS
if (exitCode != 0) if (exitCode != 0)
{ {
if (!getFlags().noOutput) fprintf(stderr, "Updating failed! (cloning)\n"); if (!why2_get_flags().why2_no_output) fprintf(stderr, "Updating failed! (cloning)\n");
return UPDATE_FAILED; return WHY2_WHY2_UPDATE_FAILED;
} }
//COUNT installCommand LENGTH & ALLOCATE IT //COUNT installCommand LENGTH & ALLOCATE IT
installCommand = replaceWord(UPDATE_COMMAND, "{DIR}", UPDATE_NAME); installCommand = replaceWord(WHY2_UPDATE_COMMAND, "{DIR}", WHY2_UPDATE_NAME);
installCode = system(installCommand); //INSTALL installCode = system(installCommand); //INSTALL
//REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN //REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN
remove(VERSIONS_NAME); remove(WHY2_VERSIONS_NAME);
free(installCommand); free(installCommand);
//CHECK FOR ERRORS //CHECK FOR ERRORS
if (installCode != 0) if (installCode != 0)
{ {
if (!getFlags().noOutput) fprintf(stderr, "Updating failed! (installing)\n"); if (!why2_get_flags().why2_no_output) fprintf(stderr, "Updating failed! (installing)\n");
return UPDATE_FAILED; return WHY2_WHY2_UPDATE_FAILED;
} }
goto deallocation; //GREAT SUCCESS! goto deallocation; //GREAT WHY2_SUCCESS!
} }
//COUNT VERSIONS BEHIND //COUNT WHY2_VERSIONS BEHIND
int versionsIndex = -1; int versionsIndex = -1;
int versionsBuffer = 0; int versionsBuffer = 0;
@ -235,7 +235,7 @@ enum EXIT_CODES checkVersion(void)
for (int i = 0; i < (int) json_object_array_length(deprecated); i++) for (int i = 0; i < (int) json_object_array_length(deprecated); i++)
{ {
//IT'S A MATCH, BABY :D //IT'S A MATCH, BABY :D
if (strcmp(json_object_get_string(json_object_array_get_idx(deprecated, i)), VERSION) == 0) if (strcmp(json_object_get_string(json_object_array_get_idx(deprecated, i)), WHY2_VERSION) == 0)
{ {
versionsIndex = i; versionsIndex = i;
@ -243,10 +243,10 @@ enum EXIT_CODES checkVersion(void)
} }
} }
//versions.json DOESN'T CONTAIN VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT) //versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT)
if (versionsIndex == -1) if (versionsIndex == -1)
{ {
if (!getFlags().noOutput) printf("Version %s not found! Check your flags.\n\n", VERSION); if (!why2_get_flags().why2_no_output) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION);
goto deallocation; goto deallocation;
} }
@ -254,7 +254,7 @@ enum EXIT_CODES checkVersion(void)
//COUNT versionsBuffer //COUNT versionsBuffer
versionsBuffer = json_object_array_length(deprecated) - versionsIndex; versionsBuffer = json_object_array_length(deprecated) - versionsIndex;
if (!getFlags().noOutput) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, VERSION, json_object_get_string(active)); if (!why2_get_flags().why2_no_output) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, WHY2_VERSION, json_object_get_string(active));
//WAIT FOR 5 SECONDS //WAIT FOR 5 SECONDS
sleep(5); sleep(5);
@ -266,10 +266,10 @@ enum EXIT_CODES checkVersion(void)
json_object_put(parsedJson); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT json_object_put(parsedJson); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT
free(buffer); free(buffer);
return SUCCESS; return WHY2_SUCCESS;
} }
void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize) void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize)
{ {
int numberBuffer; int numberBuffer;
int numberBuffer2; int numberBuffer2;
@ -279,13 +279,13 @@ void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize)
{ {
numberBuffer = i; numberBuffer = i;
//CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT UNUSED LENGTH //CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH
while (numberBuffer >= (int) getKeyLength()) while (numberBuffer >= (int) why2_get_key_length())
{ {
numberBuffer -= getKeyLength(); numberBuffer -= why2_get_key_length();
} }
numberBuffer2 = getKeyLength() - (numberBuffer + (i < textKeyChainSize)); numberBuffer2 = why2_get_key_length() - (numberBuffer + (i < textKeyChainSize));
//FILL textKeyChain //FILL textKeyChain
if ((numberBuffer + 1) % 3 == 0) if ((numberBuffer + 1) % 3 == 0)
@ -305,13 +305,13 @@ void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize)
} }
} }
void deallocateOutput(outputFlags flags) void why2_deallocate_output(why2_output_flags flags)
{ {
free(flags.outputText); free(flags.outputText);
free(flags.usedKey); free(flags.usedKey);
flags.elapsedTime = 0; flags.elapsedTime = 0;
flags.exitCode = SUCCESS; flags.exitCode = WHY2_SUCCESS;
flags.repeatedKeySize = 0; flags.repeatedKeySize = 0;
flags.unusedKeySize = 0; flags.unusedKeySize = 0;
@ -319,29 +319,29 @@ void deallocateOutput(outputFlags flags)
flags.usedKey = NULL; flags.usedKey = NULL;
} }
enum EXIT_CODES checkKey(char *key) enum WHY2_EXIT_CODES why2_check_key(char *key)
{ {
if (strlen(key) < getKeyLength()) if (strlen(key) < why2_get_key_length())
{ {
if (!getFlags().noOutput) fprintf(stderr, "Key must be at least %lu characters long!\n", getKeyLength()); if (!why2_get_flags().why2_no_output) fprintf(stderr, "Key must be at least %lu characters long!\n", why2_get_key_length());
return INVALID_KEY; return WHY2_INVALID_KEY;
} }
return SUCCESS; return WHY2_SUCCESS;
} }
enum EXIT_CODES checkText(char *text) enum WHY2_EXIT_CODES why2_check_text(char *text)
{ {
if (strcmp(text, "") == 0) if (strcmp(text, "") == 0)
{ {
if (!getFlags().noOutput) fprintf(stderr, "No text to encrypt!\n"); if (!why2_get_flags().why2_no_output) fprintf(stderr, "No text to encrypt!\n");
return INVALID_TEXT; return WHY2_INVALID_TEXT;
} }
return SUCCESS; return WHY2_SUCCESS;
} }
unsigned long countIntLength(int number) unsigned long why2_count_int_length(int number)
{ {
int returning = 1; int returning = 1;
int buffer = 10; int buffer = 10;
@ -363,7 +363,7 @@ unsigned long countIntLength(int number)
return returning; return returning;
} }
unsigned long countUnusedKeySize(char *text, char *key) unsigned long why2_count_unused_key_size(char *text, char *key)
{ {
unsigned long returning = 0; unsigned long returning = 0;
@ -375,7 +375,7 @@ unsigned long countUnusedKeySize(char *text, char *key)
return returning; return returning;
} }
unsigned long countRepeatedKeySize(char *text, char *key) unsigned long why2_count_repeated_key_size(char *text, char *key)
{ {
unsigned long returning = 0; unsigned long returning = 0;
@ -387,12 +387,12 @@ unsigned long countRepeatedKeySize(char *text, char *key)
return returning; return returning;
} }
unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime) unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime)
{ {
return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec; return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec;
} }
void generateKey(char *key, int keyLength) void why2_generate_key(char *key, int keyLength)
{ {
int numberBuffer; int numberBuffer;

View File

@ -21,16 +21,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdio.h> #include <stdio.h>
//VARIABLES //VARIABLES
logFlags flags = { NULL }; why2_log_flags flags = { NULL };
//GETTERS //GETTERS
logFlags getLogFlags(void) why2_log_flags why2_get_log_flags(void)
{ {
return flags; return flags;
} }
//SETTERS //SETTERS
void setLogFlags(logFlags logFlagsNew) void why2_set_log_flags(why2_log_flags why2_log_flagsNew)
{ {
flags = logFlagsNew; flags = why2_log_flagsNew;
} }

View File

@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/encrypter.h> #include <why2/encrypter.h>
#include <why2/misc.h> #include <why2/misc.h>
logFile initLogger(char *directoryPath) why2_log_file why2_init_logger(char *directoryPath)
{ {
//VARIABLES //VARIABLES
struct stat st; struct stat st;
@ -41,13 +41,13 @@ logFile initLogger(char *directoryPath)
struct tm tm = *localtime(&timeL); struct tm tm = *localtime(&timeL);
int buffer = 1; int buffer = 1;
int file; int file;
char *filePath = malloc(strlen(directoryPath) + 1 + strlen(LOG_FORMAT) + 1); char *filePath = malloc(strlen(directoryPath) + 1 + strlen(WHY2_LOG_FORMAT) + 1);
char *dateBuffer = malloc(strlen(LOG_FORMAT_START) + 1); char *dateBuffer = malloc(strlen(WHY2_LOG_FORMAT_START) + 1);
char *latestBuffer = malloc(strlen(WRITE_DIR) + strlen(LOG_LATEST) + 2); char *latestBuffer = malloc(strlen(WHY2_WRITE_DIR) + strlen(WHY2_LOG_LATEST) + 2);
char *latestFilePath = NULL; char *latestFilePath = NULL;
DIR *dir; DIR *dir;
sprintf(dateBuffer, LOG_FORMATTING_START, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); sprintf(dateBuffer, WHY2_LOG_FORMATTING_START, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
//CREATE directoryPath DIRECTORY IF IT DOESN'T EXISTS ALREADY //CREATE directoryPath DIRECTORY IF IT DOESN'T EXISTS ALREADY
if (stat(directoryPath, &st) == -1) if (stat(directoryPath, &st) == -1)
@ -65,24 +65,24 @@ logFile initLogger(char *directoryPath)
} }
} }
if (buffer > MAX_USAGE) //MAX_USAGE WAS REACHED if (buffer > WHY2_MAX_USAGE) //WHY2_MAX_USAGE WAS REACHED
{ {
file = INVALID_FILE; file = INVALID_FILE;
goto deallocation; goto deallocation;
} }
sprintf(filePath, LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME sprintf(filePath, WHY2_LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME
file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE
//CREATE SYMLINK //CREATE SYMLINK
sprintf(latestBuffer, LOG_LATEST_FORMATTING, WRITE_DIR, LOG_LATEST); //GENERATE LATEST.log PATH sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, WHY2_WRITE_DIR, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH
latestFilePath = strdup(filePath); latestFilePath = strdup(filePath);
if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS
(void) (symlink(latestFilePath + (strlen(WRITE_DIR) + 1), latestBuffer) + 1); //TODO: Try to create some function for processing exit value //CREATE (void) (symlink(latestFilePath + (strlen(WHY2_WRITE_DIR) + 1), latestBuffer) + 1); //TODO: Try to create some function for processing exit value //CREATE
deallocation: deallocation:
@ -92,14 +92,14 @@ logFile initLogger(char *directoryPath)
free(latestFilePath); free(latestFilePath);
closedir(dir); closedir(dir);
return (logFile) return (why2_log_file)
{ {
file, file,
filePath filePath
}; };
} }
void writeLog(int loggerFile, char *logMessage) void why2_write_log(int loggerFile, char *logMessage)
{ {
//CHECK IF loggerFile IS CREATED //CHECK IF loggerFile IS CREATED
if (loggerFile == INVALID_FILE) if (loggerFile == INVALID_FILE)
@ -119,28 +119,28 @@ void writeLog(int loggerFile, char *logMessage)
char *message = NULL; //FINAL MESSAGE char *message = NULL; //FINAL MESSAGE
time_t timeL = time(NULL); time_t timeL = time(NULL);
struct tm tm = *localtime(&timeL); struct tm tm = *localtime(&timeL);
logFlags flags = getLogFlags(); why2_log_flags flags = why2_get_log_flags();
//SET ENCRYPTER FLAGS //SET ENCRYPTER FLAGS
if (!getFlagsChanged()) setFlags((inputFlags) { 0, 1, 0 }); if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0 });
if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED
{ {
outputFlags encrypted = encryptText(logMessageUsed, flags.key); //ENCRYPT why2_output_flags encrypted = why2_encrypt_text(logMessageUsed, flags.key); //ENCRYPT
message = strdup(encrypted.outputText); //COPY message = strdup(encrypted.outputText); //COPY
//DEALLOCATION //DEALLOCATION
deallocateOutput(encrypted); why2_deallocate_output(encrypted);
free(logMessageUsed); //I COULD DO THIS SMART SOMEHOW, BUT I AM TOO LAZY FOR THAT SHIT free(logMessageUsed); //I COULD DO THIS SMART SOMEHOW, BUT I AM TOO LAZY FOR THAT SHIT
} else //FUCK ENCRYPTION, LET'S DO IT; WHY WOULD WE EVEN USE WHY2-CORE? HUH? } else //FUCK ENCRYPTION, LET'S DO IT; WHY WOULD WE EVEN USE WHY2-CORE? HUH?
{ {
message = logMessageUsed; message = logMessageUsed;
} }
buffer = malloc(strlen(WRITE_FORMAT) + strlen(message) + 2); //ALLOCATE buffer = malloc(strlen(WHY2_WRITE_FORMAT) + strlen(message) + 2); //ALLOCATE
sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, message); //LOAD MESSAGE sprintf(buffer, WHY2_WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, message); //LOAD MESSAGE
(void) (write(loggerFile, buffer, strlen(buffer)) + 1); //TODO: Try to create some function for processing exit value (void) (write(loggerFile, buffer, strlen(buffer)) + 1); //TODO: Try to create some function for processing exit value

View File

@ -25,36 +25,36 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void) int main(void)
{ {
//VARIABLES //VARIABLES
logFile logger = initLogger(WRITE_DIR); //INITIALIZE LOGGER FILE why2_log_file logger = why2_init_logger(WHY2_WRITE_DIR); //INITIALIZE LOGGER FILE
char *usedKey = malloc(getKeyLength() + 1); char *usedKey = malloc(why2_get_key_length() + 1);
decryptedOutput decrypted; why2_decrypted_output decrypted;
int exitCode = 0; int exitCode = 0;
//GENERATE KEY //GENERATE KEY
generateKey(usedKey, getKeyLength()); why2_generate_key(usedKey, why2_get_key_length());
//FLAGS //FLAGS
logFlags flags = why2_log_flags flags =
{ {
usedKey usedKey
}; };
//SET FLAGS //SET FLAGS
setLogFlags(flags); why2_set_log_flags(flags);
//WRITE //WRITE
writeLog(logger.file, WRITE_MESSAGE_1); why2_write_log(logger.file, WHY2_WRITE_MESSAGE_1);
writeLog(logger.file, WRITE_MESSAGE_2); why2_write_log(logger.file, WHY2_WRITE_MESSAGE_2);
writeLog(logger.file, WRITE_MESSAGE_3); why2_write_log(logger.file, WHY2_WRITE_MESSAGE_3);
decrypted = decryptLogger(logger); //DECRYPT decrypted = why2_decrypt_logger(logger); //DECRYPT
//COMPARE OUTPUT //COMPARE OUTPUT
if //SUCCESS //TODO: Make this smart somehow if //WHY2_SUCCESS //TODO: Make this smart somehow
( (
strcmp(decrypted.decryptedText[0], WRITE_MESSAGE_1) == 0 && strcmp(decrypted.decryptedText[0], WHY2_WRITE_MESSAGE_1) == 0 &&
strcmp(decrypted.decryptedText[1], WRITE_MESSAGE_2) == 0 && strcmp(decrypted.decryptedText[1], WHY2_WRITE_MESSAGE_2) == 0 &&
strcmp(decrypted.decryptedText[2], WRITE_MESSAGE_3) == 0 strcmp(decrypted.decryptedText[2], WHY2_WRITE_MESSAGE_3) == 0
) )
{ {
printf printf
@ -75,8 +75,8 @@ int main(void)
//DEALLOCATION //DEALLOCATION
free(usedKey); free(usedKey);
deallocateLogger(logger); why2_deallocate_logger(logger);
deallocateDecryptedOutput(decrypted); why2_deallocate_decrypted_output(decrypted);
return exitCode; return exitCode;
} }

View File

@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/flags.h> #include <why2/logger/flags.h>
void deallocateLogger(logFile logger) void why2_deallocate_logger(why2_log_file logger)
{ {
close(logger.file); close(logger.file);
free(logger.fileName); free(logger.fileName);
@ -38,7 +38,7 @@ void deallocateLogger(logFile logger)
logger.file = INVALID_FILE; logger.file = INVALID_FILE;
} }
void deallocateDecryptedOutput(decryptedOutput output) void why2_deallocate_decrypted_output(why2_decrypted_output output)
{ {
for (unsigned long i = 0; i < output.length; i++) for (unsigned long i = 0; i < output.length; i++)
{ {
@ -49,10 +49,10 @@ void deallocateDecryptedOutput(decryptedOutput output)
free(output.decryptedText); free(output.decryptedText);
} }
decryptedOutput decryptLogger(logFile logger) why2_decrypted_output why2_decrypt_logger(why2_log_file logger)
{ {
FILE *file = fdopen(logger.file, "r"); FILE *file = fdopen(logger.file, "r");
outputFlags outputBuffer; why2_output_flags outputBuffer;
char *rawContent; char *rawContent;
char **content; char **content;
char **contentDecrypted; char **contentDecrypted;
@ -85,11 +85,11 @@ decryptedOutput decryptLogger(logFile logger)
{ {
if (rawContent[i] == '\n') //END OF ONE LINE if (rawContent[i] == '\n') //END OF ONE LINE
{ {
content[contentIndexBuffer] = calloc((i - (startingAtBuffer + strlen(WRITE_FORMAT)) + 2), sizeof(char)); //ALLOCATE ELEMENT content[contentIndexBuffer] = calloc((i - (startingAtBuffer + strlen(WHY2_WRITE_FORMAT)) + 2), sizeof(char)); //ALLOCATE ELEMENT
for (int j = startingAtBuffer + strlen(WRITE_FORMAT); j <= i; j++) //LOAD CONTENT OF EACH LINE for (int j = startingAtBuffer + strlen(WHY2_WRITE_FORMAT); j <= i; j++) //LOAD CONTENT OF EACH LINE
{ {
content[contentIndexBuffer][j - (startingAtBuffer + strlen(WRITE_FORMAT))] = rawContent[j]; //SET content[contentIndexBuffer][j - (startingAtBuffer + strlen(WHY2_WRITE_FORMAT))] = rawContent[j]; //SET
} }
contentIndexBuffer++; contentIndexBuffer++;
@ -99,19 +99,19 @@ decryptedOutput decryptLogger(logFile logger)
for (int i = 0; i < lines; i++) //DECRYPT content for (int i = 0; i < lines; i++) //DECRYPT content
{ {
outputBuffer = decryptText(content[i], getLogFlags().key); //DECRYPT outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT
contentDecrypted[i] = strdup(outputBuffer.outputText); //COPY contentDecrypted[i] = strdup(outputBuffer.outputText); //COPY
deallocateOutput(outputBuffer); //DEALLOCATE outputBuffer why2_deallocate_output(outputBuffer); //DEALLOCATE outputBuffer
} }
//DEALLOCATION //DEALLOCATION
free(rawContent); free(rawContent);
fclose(file); fclose(file);
deallocateDecryptedOutput((decryptedOutput) { content, lines }); //fuck the system lmao why2_deallocate_decrypted_output((why2_decrypted_output) { content, lines }); //fuck the system lmao
return (decryptedOutput) return (why2_decrypted_output)
{ {
contentDecrypted, contentDecrypted,
lines lines