def find_generator(p):
    '\n    The order of any element in a group can be divided by p-1.\n    Step 1: Calculate all Divisors.\n    Step 2: Test for a random element e of G wether e to the power of a Divisor is 1.\n            if neither is one but e to the power of p-1, a generator is found.\n    '
    testGen = randint(1, p)
    listTested = []
    listTested.append(testGen)
    divisors = find_divisors(p)
    while (len(listTested) < (p - 1)):
        if (testGen in listTested):
            for div in divisors:
                testPotency = (math.pow(testGen, div) % (p + 1))
                if ((testPotency == 1.0) and (div != divisors[(- 1)])):
                    break
                elif ((testPotency == 1.0) and (div == divisors[(- 1)])):
                    return testGen
        testGen = randint(1, p)
        listTested.append(testGen)
The order of any element in a group can be divided by p-1.
Step 1: Calculate all Divisors.
Step 2: Test for a random element e of G wether e to the power of a Divisor is 1.
        if neither is one but e to the power of p-1, a generator is found.
def find_generator(p):
    '\n    The order of any element in a group can be divided by p-1.\n    Step 1: Calculate all Divisors.\n    Step 2: Test for a random element e of G wether e to the power of a Divisor is 1.\n            if neither is one but e to the power of p-1, a generator is found.\n    '
    testGen = randint(1, p)
    listTested = []
    listTested.append(testGen)
    divisors = find_divisors(p)
    while (len(listTested) < (p - 1)):
        if (testGen in listTested):
            for div in divisors:
                testPotency = (math.pow(testGen, div) % (p + 1))
                if ((testPotency == 1.0) and (div != divisors[(- 1)])):
                    break
                elif ((testPotency == 1.0) and (div == divisors[(- 1)])):
                    return testGen
        testGen = randint(1, p)
        listTested.append(testGen)