int main() { /* program to find a trap-door prime */ BOOL found; int i,spins; long seed; big pp[NPRIMES],q,p,t; FILE *fp; mirsys(50,0); for (i=0;i<NPRIMES;i++) pp[i]=mirvar(0); q=mirvar(0); t=mirvar(0); p=mirvar(0); printf("Enter 9 digit seed= "); scanf("%ld",&seed); getchar(); irand(seed); printf("Enter 4 digit seed= "); scanf("%d",&spins); getchar(); for (i=0;i<spins;i++) brand(); convert(2,pp[0]); do { /* find prime p = 2.pp[1].pp[2]....+1 */ convert(2,p); for (i=1;i<NPRIMES-1;i++) { /* generate all but last prime */ bigdig(i+6,10,q); nxprime(q,pp[i]); multiply(p,pp[i],p); } do { /* find last prime component such that p is prime */ nxprime(q,q); copy(q,pp[NPRIMES-1]); multiply(p,pp[NPRIMES-1],t); incr(t,1,t); } while(!isprime(t)); copy(t,p); found=TRUE; for (i=0;i<NPRIMES;i++) { /* check that PROOT is a primitive root */ decr(p,1,q); divide(q,pp[i],q); powltr(PROOT,q,p,t); if (size(t)==1) { found=FALSE; break; } } } while (!found); fp=fopen("prime.dat","wt"); fprintf(fp,"%d\n",NPRIMES); for (i=0;i<NPRIMES;i++) cotnum(pp[i],fp); fclose(fp); printf("prime= \n"); cotnum(p,stdout); return 0; }
int main() { FILE *fp; big e,n,a,b,x,y,r; epoint *g; ebrick binst; int i,d,ndig,nb,best,time,store,base,bits; miracl *mip=mirsys(50,0); n=mirvar(0); e=mirvar(0); a=mirvar(0); b=mirvar(0); x=mirvar(0); y=mirvar(0); r=mirvar(0); fp=fopen("common.ecs","r"); fscanf(fp,"%d\n",&bits); mip->IOBASE=16; cinnum(n,fp); cinnum(a,fp); cinnum(b,fp); cinnum(r,fp); cinnum(x,fp); cinnum(y,fp); mip->IOBASE=10; printf("modulus is %d bits in length\n",logb2(n)); printf("Enter size of exponent in bits = "); scanf("%d",&nb); getchar(); ebrick_init(&binst,x,y,a,b,n,nb); printf("%d big numbers have been precomputed and stored\n",binst.store); bigdig(nb,2,e); /* random exponent */ printf("naive method\n"); ecurve_init(a,b,n,MR_PROJECTIVE); g=epoint_init(); epoint_set(x,y,0,g); ecurve_mult(e,g,g); epoint_get(g,x,y); cotnum(x,stdout); cotnum(y,stdout); printf("Brickel et al method\n"); mul_brick(&binst,e,x,y); ebrick_end(&binst); cotnum(x,stdout); cotnum(y,stdout); return 0; }
int main() { FILE *fp; int m,a,b,c; big e,a2,a6,x,y,r; epoint *g; ebrick2 binst; int i,d,ndig,nb,best,time,store,base; miracl *mip=mirsys(50,0); e=mirvar(0); a2=mirvar(0); a6=mirvar(0); x=mirvar(0); y=mirvar(0); r=mirvar(0); fp=fopen("common2.ecs","r"); fscanf(fp,"%d\n",&m); mip->IOBASE=16; cinnum(a2,fp); cinnum(a6,fp); cinnum(r,fp); cinnum(x,fp); cinnum(y,fp); mip->IOBASE=10; fscanf(fp,"%d\n",&a); fscanf(fp,"%d\n",&b); fscanf(fp,"%d\n",&c); printf("modulus is %d bits in length\n",m); printf("Enter size of exponent in bits = "); scanf("%d",&nb); getchar(); ebrick2_init(&binst,x,y,a2,a6,m,a,b,c,nb); printf("%d big numbers have been precomputed and stored\n",binst.store); bigdig(nb,2,e); /* random exponent */ printf("naive method\n"); ecurve2_init(m,a,b,c,a2,a6,FALSE,MR_PROJECTIVE); g=epoint2_init(); epoint2_set(x,y,0,g); ecurve2_mult(e,g,g); epoint2_get(g,x,y); cotnum(x,stdout); cotnum(y,stdout); zero(x); zero(y); printf("Brickel et al method\n"); mul2_brick(&binst,e,x,y); ebrick2_end(&binst); cotnum(x,stdout); cotnum(y,stdout); return 0; }