refactoring ready

This commit is contained in:
PoliEcho 2024-12-08 20:26:05 +01:00
parent 2c2f275d32
commit 5de5a70003
4 changed files with 52 additions and 6 deletions

View File

@ -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

38
src/crypt.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <cryptopp/aes.h>
#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/modes.h>
#include <iomanip>
#include <iostream>
#include <string>
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<CryptoPP::AES>::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;
}

View File

@ -2,9 +2,11 @@
#include <iostream>
#include <unistd.h>
void safe_exit(int code) {
try {
std::clog << "Exiting\n";
std::clog << "Exiting\n";
close(serverSocket);
close(serverSocket);
} catch (...) {
}
exit(code);
}

View File

@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
@ -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);