Task1 Function
Task1 Function
h>
#include <openssl/bn.h>
// print function
void printBN(char *msg, BIGNUM *a)
{
/* Use BN_bn2hex(a) for hex string
* Use BN_bn2dec(a) for decimal string */
char *number_str = BN_bn2hex(a);
printf("%s %s\n", msg, number_str);
OPENSSL_free(number_str);
}
BN_hex2bn(&H, "1");
BN_sub(p_minus, p, H);
BN_sub(q_minus, q, H);
BN_mul(phi, p_minus, q_minus, ctx);
BN_mod_inverse(d, e, phi, ctx);
BN_CTX_free(ctx);
return d; // Returning the pointer to d
}
int main()
{
BIGNUM *d = BN_new();
// I'm initializing the parameters to be passed to the function here, then
calling the function and storing the return value in d.
BIGNUM *P = BN_new();
BIGNUM *Q = BN_new();
BIGNUM *E = BN_new();
BN_hex2bn(&P, "F7E75FDC469067FFDC4E847C51F452DF");
BN_hex2bn(&Q, "E85CED54AF57E53E092113E62F436F4F");
BN_hex2bn(&E, "0D88C3");
d = Calculate_d(P, Q, E);
printBN(" d = e⁻¹ mod Φ 😈= ", d); // open the unicode keyboard to use emojis 😈
return 0;
}