Function input: a big prime number p, type BigInteger
Function return value: the generator output prime field p a g, type BigInteger
CodePudding user response:
Public static BigInteger getG (BigInteger p, BigInteger p_MinusOne) {BigInteger g=null;
OutterLoop: for (int I=2; i <50; I++) {
For (int x1=1; The x1 & lt;=Integer. The valueOf (p_MinusOne. ToString ()); {x1 + +)
Strings str1=String. The valueOf (I);
String=str2 String. The valueOf (x1);
BigInteger tmp1=new BigInteger (str1);
BigInteger tmp2=new BigInteger (str2);
If (tmp1. ModPow (tmp2, p). CompareTo (ONE)==0 & amp; & Tmp2.com pareTo (p_MinusOne)==1) {
break;
} else if (tmp1 modPow (tmp2, p). CompareTo (ONE)==0 & amp; & Tmp2.com pareTo (p_MinusOne)==0) {
G=tmp1;
Break outterLoop;
}
}
}
Return g;
}
CodePudding user response: