|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
/**written by Cracker007. 02/09/2010**/
#include <stdio.h>
#include <time.h>
#include <gmp.h>
void NextA(mpz_t ai, mpz_t xi, mpz_t n)
{
if(mpz_fdiv_ui(xi,3UL)==0UL)
{
mpz_mul_2exp(ai,ai,1UL);
mpz_mod(ai,ai,n);
}
else if(mpz_fdiv_ui(xi,3UL)==1UL)
{
mpz_add_ui(ai,ai,1UL);
mpz_mod(ai,ai,n);
}
}
void NextB(mpz_t bi, mpz_t xi, mpz_t n)
{
if(mpz_fdiv_ui(xi,3UL)==0UL)
{
mpz_mul_2exp(bi,bi,1UL);
mpz_mod(bi,bi,n);
}
else if(mpz_fdiv_ui(xi,3UL)==2UL)
{
mpz_add_ui(bi,bi,1UL);
mpz_mod(bi,bi,n);
}
}
void NextX(mpz_t xi, mpz_t a, mpz_t b, mpz_t p, mpz_t tmp)
{
if(mpz_fdiv_ui(xi,3UL)==1UL)
{
mpz_mul(tmp,a,xi);
mpz_mod(xi,tmp,p);
}
else if(mpz_fdiv_ui(xi,3UL)==2UL)
{
mpz_mul(tmp,b,xi);
mpz_mod(xi,tmp,p);
}
else
{
mpz_powm_ui(xi,xi,2UL,p);
}
}
int main()
{
clock_t start,finish;
double duration;
mpz_t p,n,a,b,tmp,t1,t2,t3;
mpz_t ai,bi,xi,a2i,b2i,x2i;
gmp_randstate_t st;
gmp_randinit_mt(st);
start=clock();
printf("calculating..\n");
mpz_inits(p,n,a,b,tmp,ai,bi,xi,a2i,b2i,x2i,t1,t2,t3,0);
mpz_set_str(p,"1988889263787723397",0);
mpz_sub_ui(n,p,1UL);
mpz_set_str(a,"5",0);
mpz_set_str(b,"443682463790746787",0);
gmp_randseed_ui(st,srand((unsigned int)time(0)));
do
{
mpz_urandomm(ai,st,n);
mpz_urandomm(bi,st,n);
mpz_powm(t1,a,ai,p);
mpz_powm(t2,b,bi,p);
mpz_mul(t3,t1,t2);
mpz_mod(xi,t3,p);
NextA(ai,xi,n);
NextB(bi,xi,n);
NextX(xi,a,b,p,tmp);
mpz_set(a2i,ai);
mpz_set(b2i,bi);
mpz_set(x2i,xi);
NextA(a2i,x2i,n);
NextB(b2i,x2i,n);
NextX(x2i,a,b,p,tmp);
while(mpz_cmp(xi,x2i)!=0)
{
NextA(ai,xi,n);
NextB(bi,xi,n);
NextX(xi,a,b,p,tmp);
NextA(a2i,x2i,n);
NextB(b2i,x2i,n);
NextX(x2i,a,b,p,tmp);
NextA(a2i,x2i,n);
NextB(b2i,x2i,n);
NextX(x2i,a,b,p,tmp);
}
mpz_sub(bi,bi,b2i);
}while(mpz_sgn(bi)==0);
mpz_sub(a2i,a2i,ai);
printf("a2i-ai=");
mpz_out_str(0,10,a2i);
printf("\nbi-b2i=");
mpz_out_str(0,10,bi);
printf("\n");
mpz_clears(p,n,a,b,tmp,ai,bi,xi,a2i,b2i,x2i,t1,t2,t3);
finish=clock();
duration=(double)(finish-start)/CLOCKS_PER_SEC;
printf("total minutes spent: %f\n",duration/60);
printf("now please use \"msolve(a2i-ai=(bi-b2i)*z,n)\" in maple to get z!\n");
system("pause");
return 0;
}
大家看看吧,起码我好像看不懂,看懂得跟大伙说说吧。嘻嘻^_^
|
|