Untitled
unknown
plain_text
2 years ago
1.1 kB
10
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();
// Initialize given values
BIGNUM *n = BN_new();
BN_set_word(n, 69353);
BIGNUM *M = BN_new();
BN_set_word(M, 12345);
BIGNUM *C = BN_new();
// Hypothetically calculated 'e' (This is a placeholder for demonstration)
BIGNUM *e = BN_new();
// Assuming e has been calculated correctly; here we simply set it for demonstration.
// In a real application, finding e from d without phi(n) would require additional steps.
BN_set_word(e, 2753); // This is a placeholder. Replace 2753 with the actual value of e obtained through calculations.
// Encryption: C = M^e mod n
BN_mod_exp(C, M, e, n, ctx);
printBN("Calculated e: ", e);
printBN("Ciphertext C: ", C);
// Cleanup
BN_free(n);
BN_free(M);
BN_free(e);
BN_free(C);
BN_CTX_free(ctx);
return 0;
}Editor is loading...
Leave a Comment