Untitled
unknown
plain_text
a year ago
878 B
6
Indexable
#include <openssl/bn.h> #include <stdio.h> void printBN(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(); BIGNUM *n = BN_new(); BIGNUM *e = BN_new(); BIGNUM *M = BN_new(); BIGNUM *d = BN_new(); BIGNUM *C = BN_new(); // Initialize n, e, M BN_set_word(n, 6887); BN_set_word(e, 143); BN_set_word(M, 1234); // Task-specific code to find d and calculate C // Since direct factorization and phi calculation are not shown here, let's assume d is found // Encryption: C = M^e mod n BN_mod_exp(C, M, e, n, ctx); printBN("Ciphertext C: ", C); // Cleanup BN_free(n); BN_free(e); BN_free(M); BN_free(d); BN_free(C); BN_CTX_free(ctx); }
Editor is loading...
Leave a Comment