-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
60 lines (45 loc) · 1.41 KB
/
test.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include "mg.h"
int main() {
// Initialize variables
mg_t mg;
mpz_t number;
mpz_t number2;
mpz_t reference;
mpz_init(number);
mpz_init(number2);
mpz_init(reference);
// Example modulus (replace with your own value)
mpz_t modulus;
mpz_init_set_str(modulus, "447183295099964424624663934151", 10);
gmp_printf("modulus: %Zd\n", modulus);
// Initialize Montgomery structure
mg_init(&mg, modulus);
print_mg_struct(&mg);
// Example number (replace with your own value)
mpz_set_ui(number, 123456);
mpz_set_ui(number2, 222100);
mpz_mul(reference, number, number2);
mpz_mod(reference, reference, modulus);
gmp_printf("number: %Zd\n", number);
gmp_printf("number2: %Zd\n", number2);
// Convert number to Montgomery form
mg_i2mg(&mg, number);
mg_i2mg(&mg, number2);
gmp_printf("mg number: %Zd\n", number);
gmp_printf("mg number2: %Zd\n", number2);
mpz_mul(number, number, number2);
mg_redc(&mg, number);
// Convert number back from Montgomery form
mg_mg2i(&mg, number);
// Output the result
gmp_printf("multiplied and converted back: %Zd\n", number);
gmp_printf("multiplied original result: %Zd\n", reference);
// Release resources
mpz_clear(number);
mpz_clear(modulus);
mpz_clear(number2);
mpz_clear(reference);
mg_release(&mg);
return 0;
}