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
|
#include<gmp.h> #include<time.h> #include<stdio.h> #include<stdlib.h> gmp_randstate_t gmp_state; __mpz_struct p,q,n_,e,p_1,q_1,lambda,d_; __mpz_struct secret,msg; char* data,data1;
int main(){ data=malloc(0x2000); data1=malloc(0x2000); __gmpz_inits(&p,&q,&n_,&e,&p_1,&q_1,&lambda,&d_,&secret,&msg,0); __gmp_randinit_mt(&gmp_state); long long int num=0; scanf("%lld",&num); __gmp_randseed_ui(&gmp_state,time(0)+num); __gmpz_urandomb(&q,&gmp_state,256); __gmpz_nextprime(&q,&q); __gmpz_urandomb(&p,&gmp_state,256); __gmpz_nextprime(&p,&p); __gmpz_mul(&n_, &p, &q); __gmpz_set_ui(&e, 65537LL); __gmpz_sub_ui(&p_1, &p, 1LL); __gmpz_sub_ui(&q_1, &q, 1LL); __gmpz_lcm(&lambda, &p_1, &q_1); __gmpz_invert(&d_, &e, &lambda); printf("n: %s\n",__gmpz_get_str(0,0,&n_)); read(0,data,0x100); __gmpz_set_str(&secret,data,10); __gmpz_powm(&msg,&secret,&d_,&n_); printf("data: %s\n",__gmpz_get_str(0,0,&msg));
}
|