Home > Back-end >  The formation of a cyclic group yuan, implementation using Java code
The formation of a cyclic group yuan, implementation using Java code

Time:11-13

Topic: write a function to a cyclic group generated yuan, implementation using Java code

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:

reference 1st floor qq_38351849 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;
}


What is the meaning of p_minusOne
  • Related