summaryrefslogtreecommitdiff
path: root/euler97.c
blob: b0f55bcd28bebe1073ea9638fa0aa0db4a852ceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <openssl/bn.h>

static const unsigned char _7830457[3] = { 0x77, 0x7b, 0xb9 };
static const unsigned char _2[1] = {2};
static const unsigned char _28433[2] = {0x6f, 0x11};
static const unsigned char _10000000000[5] = {0x02, 0x54, 0x0b, 0xe4, 0x00};

int main()
{
	BIGNUM *b28433 = BN_bin2bn(_28433, 2, NULL);
	BIGNUM *b2 = BN_bin2bn(_2, 1, NULL);
	BIGNUM *b7830457 = BN_bin2bn(_7830457, 3, NULL);
	BIGNUM *b10ten = BN_bin2bn(_10000000000, 5, NULL);

	BN_CTX *ctx = BN_CTX_new();
	BIGNUM *r = BN_new();
	BIGNUM *r2 = BN_new();
	BIGNUM *r3 = BN_new();
	BN_mod_exp(r, b2, b7830457, b10ten, ctx);
	BN_mul(r2, r, b28433, ctx);
	BN_add(r3, r2, BN_value_one());
	BN_mod(r, r3, b10ten, ctx);

	unsigned char res[10];
	int len = BN_bn2mpi(r, res);
	for (int i = 0; i < len; i++)
		printf("%02x", res[i]);

	puts("");
}