<commit_before>#include <stdio.h>
#include <iostream>
#include <string>

#include "base64.h"
#include "Crypto.h"

#define PRINT_KEYS

using namespace std;

int main() {
    Crypto crypto;

    #ifdef PRINT_KEYS
        // Write the keys to stdout if compiled as such
        crypto.writeKeyToFile(stdout, KEY_SERVER_PRI);
        crypto.writeKeyToFile(stdout, KEY_SERVER_PUB);
        crypto.writeKeyToFile(stdout, KEY_CLIENT_PUB);

        unsigned char *aesKey;
        size_t aesLength = crypto.getAESKey(&aesKey);
        printf("AES key: ");
        for(unsigned int i=0; i<aesLength; i++) {
            printf("%x", aesKey[i]);
        }
        printf("\n");
    #endif

    string msg;
    unsigned char *encMsg = NULL;
    char *decMsg          = NULL;
    int encMsgLen;
    int decMsgLen;

    unsigned char *ek;
    unsigned char *iv;
    size_t ekl;
    size_t ivl;

    while(1) {
        // Get the message to encrypt
        printf("Message to RSA encrypt: ");
        fflush(stdout);
        getline(cin, msg);

        // Encrypt the message with RSA
        if((encMsgLen = crypto.rsaEncrypt((const unsigned char*)msg.c_str(), msg.size(), &encMsg, &ek, &ekl, &iv, &ivl)) == -1) {
            fprintf(stderr, "Encryption failed\n");
            return 1;
        }

        // Print the encrypted message as a base64 string
        char* b64String = base64Encode(encMsg, encMsgLen);
        printf("Encrypted message: %s\n", b64String);

        // Decrypt the message
        if((decMsgLen = crypto.rsaDecrypt(encMsg, (size_t)encMsgLen, ek, ekl, iv, ivl, (unsigned char**)&decMsg)) == -1) {
            fprintf(stderr, "Decryption failed\n");
            return 1;
        }
        printf("Decrypted message: %s\n", decMsg);

        // No one likes memory leaks
        free(encMsg);
        free(decMsg);
        free(ek);
        free(iv);
        free(b64String);
        encMsg    = NULL;
        decMsg    = NULL;
        ek        = NULL;
        iv        = NULL;
        b64String = NULL;

        // Get the message to encrypt
        printf("Message to AES encrypt: ");
        fflush(stdout);
        getline(cin, msg);

        // Encrypt the message with AES
        if((encMsgLen = crypto.aesEncrypt((const unsigned char*)msg.c_str(), msg.size(), &encMsg)) == -1) {
            fprintf(stderr, "Encryption failed\n");
            return 1;
        }

        // Print the encrypted message as a base64 string
        b64String = base64Encode(encMsg, encMsgLen);
        printf("Encrypted message: %s\n", b64String);

        // Decrypt the message
        if((decMsgLen = crypto.aesDecrypt(encMsg, (size_t)encMsgLen, (unsigned char**)&decMsg)) == -1) {
            fprintf(stderr, "Decryption failed\n");
            return 1;
        }
        printf("%d bytes decrypted\n", decMsgLen);
        printf("Decrypted message: %s\n", decMsg);

        // Memory leaks... yadda yadda yadda...
        free(encMsg);
        free(decMsg);
        free(b64String);
        encMsg    = NULL;
        decMsg    = NULL;
        b64String = NULL;
    }

    return 0;
}
<commit_msg>don't print keys by default<commit_after>#include <stdio.h>
#include <iostream>
#include <string>

#include "base64.h"
#include "Crypto.h"

//#define PRINT_KEYS

using namespace std;

int main() {
    Crypto crypto;

    #ifdef PRINT_KEYS
        // Write the RSA keys to stdout
        crypto.writeKeyToFile(stdout, KEY_SERVER_PRI);
        crypto.writeKeyToFile(stdout, KEY_SERVER_PUB);
        crypto.writeKeyToFile(stdout, KEY_CLIENT_PUB);

        // Write the AES key to stdout in hex
        unsigned char *aesKey;
        size_t aesLength = crypto.getAESKey(&aesKey);
        printf("AES key: ");
        for(unsigned int i=0; i<aesLength; i++) {
            printf("%x", aesKey[i]);
        }
        printf("\n");
    #endif

    string msg;
    unsigned char *encMsg = NULL;
    char *decMsg          = NULL;
    int encMsgLen;
    int decMsgLen;

    unsigned char *ek;
    unsigned char *iv;
    size_t ekl;
    size_t ivl;

    while(1) {
        // Get the message to encrypt
        printf("Message to RSA encrypt: ");
        fflush(stdout);
        getline(cin, msg);

        // Encrypt the message with RSA
        if((encMsgLen = crypto.rsaEncrypt((const unsigned char*)msg.c_str(), msg.size(), &encMsg, &ek, &ekl, &iv, &ivl)) == -1) {
            fprintf(stderr, "Encryption failed\n");
            return 1;
        }

        // Print the encrypted message as a base64 string
        char* b64String = base64Encode(encMsg, encMsgLen);
        printf("Encrypted message: %s\n", b64String);

        // Decrypt the message
        if((decMsgLen = crypto.rsaDecrypt(encMsg, (size_t)encMsgLen, ek, ekl, iv, ivl, (unsigned char**)&decMsg)) == -1) {
            fprintf(stderr, "Decryption failed\n");
            return 1;
        }
        printf("Decrypted message: %s\n", decMsg);

        // No one likes memory leaks
        free(encMsg);
        free(decMsg);
        free(ek);
        free(iv);
        free(b64String);
        encMsg    = NULL;
        decMsg    = NULL;
        ek        = NULL;
        iv        = NULL;
        b64String = NULL;

        // Get the message to encrypt
        printf("Message to AES encrypt: ");
        fflush(stdout);
        getline(cin, msg);

        // Encrypt the message with AES
        if((encMsgLen = crypto.aesEncrypt((const unsigned char*)msg.c_str(), msg.size(), &encMsg)) == -1) {
            fprintf(stderr, "Encryption failed\n");
            return 1;
        }

        // Print the encrypted message as a base64 string
        b64String = base64Encode(encMsg, encMsgLen);
        printf("Encrypted message: %s\n", b64String);

        // Decrypt the message
        if((decMsgLen = crypto.aesDecrypt(encMsg, (size_t)encMsgLen, (unsigned char**)&decMsg)) == -1) {
            fprintf(stderr, "Decryption failed\n");
            return 1;
        }
        printf("%d bytes decrypted\n", decMsgLen);
        printf("Decrypted message: %s\n", decMsg);

        // Memory leaks... yadda yadda yadda...
        free(encMsg);
        free(decMsg);
        free(b64String);
        encMsg    = NULL;
        decMsg    = NULL;
        b64String = NULL;
    }

    return 0;
}

{'fraction_non_alphanumeric': 0.1257992327365729, 'fraction_numerical': 0.011828644501278773, 'mean_word_length': 1.9923481587757055, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2595846', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1947, 'n_words': 509}