diff --git a/Makefile b/Makefile index a33963b..5e85e78 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ # Compiler and flags CPPC = g++ -CPPC_FLAGS = -s -O3 -lasound -Wall -Wextra -# Debug flags: -# CPPC_FLAGS = -ggdb -lncurses -lcurl -lmenu -lpanel -Wall -Wextra +CPPC_FLAGS = -s -O3 -lasound -lcryptopp -Wall -Wextra SRC_PATH := src diff --git a/src/crypt.cpp b/src/crypt.cpp new file mode 100644 index 0000000..e67a462 --- /dev/null +++ b/src/crypt.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include + +int main() { + // Key and IV (Initialization Vector) for AES + CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH] = { + 'k', 'e', 'y', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '1', '0', '1', '1'}; + CryptoPP::byte iv[CryptoPP::AES::BLOCKSIZE] = {'i', 'v', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '1', + '0', '1', '1', '1'}; + + // Message to be encrypted + std::string plainText = "Hello, AES!"; + std::string cipherText; // Declare cipherText variable + + // Encrypt using AES in CBC mode + CryptoPP::CBC_Mode::Encryption encryptor(key, sizeof(key), iv); + CryptoPP::StringSource(plainText, true, + new CryptoPP::StreamTransformationFilter( + encryptor, new CryptoPP::StringSink(cipherText))); + + // Encode the encrypted message in Base64 format + std::string base64Encoded; + CryptoPP::StringSource( + cipherText, true, + new CryptoPP::Base64Encoder(new CryptoPP::StringSink(base64Encoded))); + + // Display the Base64 encoded encrypted message + std::cout << "Encrypted Text (Base64): " << base64Encoded << std::endl; + + return 0; +} diff --git a/src/helper_funcs.cpp b/src/helper_funcs.cpp index 64841b2..7b09f61 100644 --- a/src/helper_funcs.cpp +++ b/src/helper_funcs.cpp @@ -2,9 +2,11 @@ #include #include void safe_exit(int code) { + try { + std::clog << "Exiting\n"; - std::clog << "Exiting\n"; - - close(serverSocket); + close(serverSocket); + } catch (...) { + } exit(code); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3dd0b8d..e6e8238 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,13 @@ int serverSocket; int main(int argc, char *argv[]) { + std::string SecretNumCode_s = ""; + for (char ch : SECRET) { + uint num = ch - 'a' + 1; // Convert 'a' to 1, 'b' to 2, etc. + SecretNumCode_s.append(std::to_string(num)); + } + const long SecretNumCode = std::stoi(SecretNumCode_s); + // signal handlers signal(SIGTERM, safe_exit); signal(SIGINT, safe_exit);