Ejemplo n.º 1
0
int main(){

	long double tmp = 0, aux = 2;

	for(; aux < 1000000; aux = prime_gen(++aux)){
		tmp += aux;
	}

	printf("Result : %Lf\n", tmp);

	return 0;

}
Ejemplo n.º 2
0
CryptoPpDlogZpSafePrime::CryptoPpDlogZpSafePrime(ZpGroupParams * groupParams, mt19937 prg)
{
	mt19937 prime_gen(clock()); // prg for prime checking
	this->random_element_gen = prg;
	biginteger p = groupParams->getP();
	biginteger q = groupParams->getQ();
	biginteger g = groupParams->getXg();

	// if p is not 2q+1 throw exception
	if (!(q * 2 + 1 == p)) {
		throw invalid_argument("p must be equal to 2q+1");
	}
	// if p is not a prime throw exception

	if (!miller_rabin_test(p, 40, prime_gen)) {
		throw invalid_argument("p must be a prime");
	}
	// if q is not a prime throw exception
	if (!miller_rabin_test(q, 40, prime_gen)) {
		throw invalid_argument("q must be a prime");
	}
	// set the inner parameters
	this->groupParams = groupParams;

	//Create CryptoPP Dlog group with p, ,q , g.
	//The validity of g will be checked after the creation of the group because the check need the pointer to the group
	pointerToGroup = new CryptoPP::DL_GroupParameters_GFP_DefaultSafePrime();
	pointerToGroup->Initialize(biginteger_to_cryptoppint(p), biginteger_to_cryptoppint(q), biginteger_to_cryptoppint(g));

	//If the generator is not valid, delete the allocated memory and throw exception 
	if (!pointerToGroup->ValidateElement(3, biginteger_to_cryptoppint(g), 0)){
		delete pointerToGroup;
		throw invalid_argument("generator value is not valid");
	}
	//Create the GroupElement - generator with the pointer that return from the native function
	generator = new ZpSafePrimeElementCryptoPp(g, p, false);

	//Now that we have p, we can calculate k which is the maximum length of a string to be converted to a Group Element of this group.
	k = calcK(p);
}