main() { uint64_t gcd, a, b; long long int x, y; a = 7; b = 5; eea(a,b,&gcd,&x,&y); printf("a: %lld b: %lld gcd: %lld x: %lld y: %lld",a,b,gcd,x,y); }
/* this function generates a public key, private key and modulo n for RSA encryption. srand needs to be seeded */ void generateKeys(uint64_t* pub, uint64_t* priv, uint64_t* n) { uint64_t p,q,phiN; /* generate a random p between given range until p passes the lehmann primality test function*/ do { p = ( rand() % (PMAX-PMIN) ) + PMIN; } while(!lehmann(p)); /* generate a random q between given range until q passes the lehmann primality test function*/ do { q = ( rand() % (PMAX-PMIN) ) + PMIN; } while(!lehmann(q)); /*calulate the modulo n to pass back*/ *n=p*q; /*calculate φ(n)*/ phiN =(p-1)*(q-1); uint64_t e,gcd,d; long long int xi,yi; /* calcuate e and test to see that it is co-prime with φ(n)*/ do { e = rand()%(phiN-3)+2; eea(e,phiN,&gcd,&xi,&yi); } while(gcd !=1); /* using the value fromt he EEA function, get your private key d (need to had φ(n) and mod φ(n) to make sure it is positive*/ d = (uint64_t)((xi+phiN)%phiN); /*pass back the public and private keys*/ *pub = e; *priv = d; }
int64 modInverse_relativePrime(int64 B,int64 P) { return eea(B,P).second.first; }
idt recEventEventa::Create( idt eID, idt eaID, double conf, const wxString& note ) { recEventEventa eea(eID, eaID, conf, note); eea.Save(); return eea.FGetID(); }