WHY2/src/lib/flags.c

84 lines
1.8 KiB
C
Raw Normal View History

#include <why2/flags.h>
#include <stdlib.h>
//CONSTS (this is just local)
#define DEFAULT_FLAGS (inputFlags) { 0, 0, 0 }
int encryptionOperation(int text, int encryptedText);
//VARIABLES
char encryptionSeparator = '.'; //NOPE > DO NOT TOUCH THIS, USE setEncryptionSeparator instead <
unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE setKeyLength instead <
inputFlags flags = DEFAULT_FLAGS;
encryptionOperation_type_cb encryptionOperation_cb = encryptionOperation;
//GETTERS
char getEncryptionSeparator()
{
return encryptionSeparator;
}
2022-05-29 17:45:34 +02:00
unsigned long getKeyLength()
{
return keyLength;
}
2022-07-10 17:40:32 +02:00
inputFlags defaultFlags()
2022-05-27 17:25:02 +02:00
{
return DEFAULT_FLAGS;
2022-05-27 17:25:02 +02:00
}
2022-07-10 18:10:18 +02:00
inputFlags getFlags()
{
return flags;
}
outputFlags noOutput(boolean exitCode)
{
char *emptyText = malloc(1); //TEXT
emptyText[0] = '\0';
char *emptyKey = malloc(getKeyLength() + 1); //KEY
for (int i = 0; i < (int) getKeyLength(); i++)
{
emptyKey[i] = 'x';
}
emptyKey[getKeyLength()] = '\0';
return (outputFlags) { emptyText, emptyKey, 0, 0, 0, exitCode };
}
encryptionOperation_type_cb getEncryptionOperation()
{
return encryptionOperation_cb;
}
//SETTERS
void setEncryptionSeparator(char encryptionSeparatorNew)
{
if (encryptionSeparatorNew <= 31) return;
encryptionSeparator = encryptionSeparatorNew;
}
void setKeyLength(int keyLengthNew)
{
2022-07-29 17:19:05 +02:00
if (keyLengthNew < 1) return;
keyLength = keyLengthNew;
2022-07-10 18:10:18 +02:00
}
void setFlags(inputFlags newFlags)
{
flags = newFlags;
}
2022-10-17 16:50:45 +02:00
//SOME OTHER SHIT
int encryptionOperation(int text, int encryptedText)
{
//CHANGE THE '-' (MINUS) OPERATOR TO SOMETHING YOU WANT TO USE I GUESS
return text - encryptedText;
//I DO NOT RECOMMEND CHANGING THIS, BUT IF YOU WANT TO, XOR IS A GOOD OPERATOR (IDK IF OTHERS WORK lmao)
}