Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
6
Indexable
#include <openssl/bn.h>
#include <stdio.h>

void initialize_bn(BIGNUM **bn, unsigned long value) {
    *bn = BN_new();
    BN_set_word(*bn, value);
}

void printBN(const char *msg, BIGNUM *a) {
    char *number_str = BN_bn2dec(a);
    printf("%s%s\n", msg, number_str);
    OPENSSL_free(number_str);
}

int main() {
    BN_CTX *ctx = BN_CTX_new();
    
    // Given values
    BIGNUM *n, *d, *M, *C;
    initialize_bn(&n, 69353);
    initialize_bn(&d, 29401); // Provided for context, not directly used in encryption
    initialize_bn(&M, 12345);
    C = BN_new();

    // Placeholder for the encryption key 'e', assuming calculated externally
    BIGNUM *e;
    // For demonstration, let's assume we calculated e correctly as a placeholder
    initialize_bn(&e, 1); // Placeholder, replace this with the actual calculation

    // Encryption: C = M^e mod n
    BN_mod_exp(C, M, e, n, ctx);
    printBN("Ciphertext C: ", C);

    // Cleanup
    BN_free(n);
    BN_free(d);
    BN_free(M);
    BN_free(e);
    BN_free(C);
    BN_CTX_free(ctx);

    return 0;
}
Editor is loading...
Leave a Comment