Untitled

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

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 = BN_new();
    BIGNUM *d = BN_new(); // Provided for context; not used in encryption
    BIGNUM *M = BN_new();
    BIGNUM *C = BN_new();
    BIGNUM *e = BN_new(); // The encryption key 'e' we're assuming we have found

    // Initializing given values
    BN_dec2bn(&n, "69353");
    BN_dec2bn(&d, "29401"); // Not directly used in this step
    BN_dec2bn(&M, "12345");

    // Hypothetical e value (assuming it's been calculated)
    // IMPORTANT: This value of 'e' is assumed for demonstration purposes.
    // In a real scenario, you would calculate 'e' based on 'd' and 'phi(n)'
    BN_dec2bn(&e, "65537"); // Commonly used public exponent

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

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

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