Hi all, I have been working on the program here. However, I am getting the error undefined inverse in _ntl_zinvmod when I run the program after I apply the Chinese Remainder Theorem by Number Theory Library. Any help is much appreciated! Thank you
if (((GCD(dp2, p2_)) == to_ZZ(1)) && ((dp2%2)==k4_)&& 1<dp2<p2) dp2 = dp2;
else for (; ;) {
dp2 = to_ZZ(0);
RandomBits(dp2, PrimeBitSize);
if (((GCD(dp2, p2_)) == to_ZZ(1)) && ((dp2%2)==k4_)&& 1<dp2<p2) break;
}
if (((GCD(dp3, p3_)) == to_ZZ(1)) && ((dp3%2)==k4_)&& 1<dp3<p3) dp3 = dp3;
else for (; ;) {
dp3 = to_ZZ(0);
RandomBits(dp3, PrimeBitSize);
if (((GCD(dp3, p1_)) == to_ZZ(1)) && ((dp3%2)==k4_)&& 1<dp3<p3) break;
}
if (((GCD(dp4, p4_)) == to_ZZ(1)) && ((dp4%2)==k4_)&& 1<dp4<p4) dp4 = dp4;
else for (; ;) {
dp4 = to_ZZ(0);
RandomBits(dp4, PrimeBitSize);
if (((GCD(dp4, p4_)) == to_ZZ(1)) && ((dp4%2)==k4_)&& 1<dp4<p4) break;
}
if (((GCD(dp5, p5_)) == to_ZZ(1)) && ((dp5%2)==k4_)&& 1<dp5<p5) dp5 = dp5;
else for (; ;) {
dp5 = to_ZZ(0);
RandomBits(dp5, PrimeBitSize);
if (((GCD(dp5, p5_)) == to_ZZ(1)) && ((dp5%2)==k4_)&& 1<dp5<p5) break;
}
}
ZZ solveByCRT(vec_ZZ& primes, vec_ZZ& a, int num_of_primes){
int i;
long check;
ZZ a_tmp1, a_tmp2, p_tmp1, p_tmp2;
for(i=0; i<(5-1); i++){
if(i==0) a_tmp1 = a[i];
a_tmp2 = a[i+1];
if(i==0) p_tmp1 = primes[i]-1;
p_tmp2 = primes[i+1]-1;
check = CRT(a_tmp1, p_tmp1, a_tmp2, p_tmp2); //a_tmp1 is updated with the intermediate solution
}
//p_tmp1 is updated with p_tmp1*p_tmp2
return a_tmp1; //Returns the final solution
}
int main(){
ZZ p1, p2, p3, p4, p5, n, dp1, dp2, dp3, dp4, dp5;
long ModBitSize;
SetSeed(to_ZZ(time(NULL)));
ModBitSize = 1000;
gen_rprime(p1, p2, p3, p4, p5, n, dp1, dp2, dp3, dp4, dp5, ModBitSize);
cout << "The first prime (p1) is: " << p1 << endl;
cout << "The second prime (p2) is: " << p2 << endl;
cout << "The third prime (p3) is: " << p3 << endl;
cout << "The fourth prime (p4) is: " << p4 << endl;
cout << "The fifth prime (p5) is: " << p5 << endl;
cout << "Their product (n) is: " << n << endl;
cout << "DP1 is: " << dp1 << endl;
cout << "DP2 is: " << dp2 << endl;
cout << "DP3 is: " << dp3 << endl;
cout << "DP4 is: " << dp4 << endl;
cout << "DP5 is: " << dp5 << endl;
ZZ soln; //Stores the solution to the system of equations
vec_ZZ a, primes;
a.SetLength(5); //After declaring variables of vec_ZZ type, we always
primes.SetLength(5); //need to set the length of the vectors. In this case,
//there are 3 primes, so length is 3.
a[0] = dp1; //U can try out for different numbers of primes
a[1] = dp2; //with different values of a[i]
a[2] = dp3;
a[3] = dp4;
a[4] = dp5;
primes[0] = p1; //Need to set the values of the vectors "a" and "primes"
primes[1] = p2;
primes[2] = p3;
primes[3] = p4;
primes[4] = p5;