I'm trinying to implement an algorithm to search a generator of a cyclic group G:
n is the order of the group G , and Pi is the decomposition of n to prime numbers like n = P1^e1 x P2^e2 ....x Pk^ek
this is the algorithm :
Step 1 : Choose an element g from G
Step 2 : for each i from 1 to k do
Step 2.1 : b <- pow ( g , n / Pi )
Step 2.3 : if b =1 goto step 1
Step 3 : return g
this is my implementation in java , I want to use a goto but it generate an error :
public int getGenerateur(){
List<Integer> facteur=new ArrayList<Integer>();
facteur=this.getFacteur(nombre);
double b;
int generateur=0;
boolean etape = true;
while(etape){
etape = false;
System.out.println("generateur aleatoire:");
generateur =(int) (Math.random() * (nombre - 2)) + 2;
System.out.println(generateur);
for(int s=0;s<facteur.size();s++){
b=Math.pow(generateur,(nombre/facteur.get(s)))%(nombre+1);
System.out.println("b= "+b);
if(b==1){
etape = true;
break;
}
}
}
return generateur;
}
if you use an outer loop and a break statement, you should be able to do what you want to do. It would look something like this
boolean etape = true;
while(etape){
etape = false;
System.out.println("Entrer un generateur :");
generateur = sc.nextInt();
for(int s=0;s<facteur.size();s++){
b=Math.pow(generateur,(nombre/facteur.get(s)))%(nombre+1);
System.out.println("b= "+b);
if(b==1){
etape = true;
break;
}
}
}
return generateur;