Greetings!
How do I check if an element a belongs to a specific cyclic group G of prime order, given the generator? Right now i simply generate all the elements in the group, save them into a container and check if the element is in it. This is the code im currently using to generate all the elements of the group:
public HashSet<BigInteger> group_elements(BigInteger g, BigInteger q) {
HashSet<BigInteger> group = new HashSet<BigInteger>();
BigInteger element = modPow(g,ONE,q);
for (int i = 2; !group.contains(element); i++) {
group.add(element);
element = modPow(g, BigInteger.valueOf(i), q);
}
return group;
}
And to see if a element is in the group i simply check:
if (group.contains(num)) { ... }
As you can see the language is Java