(N)
return answer
This function implements Shor's factoring algorithm on the Integer N

    The algorithm starts by picking a random number (a) and seeing if it is
    coprime with N. If it isn't, then the gcd of the two numbers is a factor
    and we are done. Otherwise, it begins the period_finding subroutine which
    finds the period of a in modulo N arithmetic. This period, if even, can
    be used to calculate factors by taking a**(r/2)-1 and a**(r/2)+1.
    These values are returned.
This function implements Shor's factoring algorithm on the Integer N
This function implements Shor s factoring algorithm on the Integer N
def shor(N):
    """This function implements Shor's factoring algorithm on the Integer N

    The algorithm starts by picking a random number (a) and seeing if it is
    coprime with N. If it isn't, then the gcd of the two numbers is a factor
    and we are done. Otherwise, it begins the period_finding subroutine which
    finds the period of a in modulo N arithmetic. This period, if even, can
    be used to calculate factors by taking a**(r/2)-1 and a**(r/2)+1.
    These values are returned.
    """
    a = random.randrange(N - 2) + 2
    if igcd(N, a) != 1:
        print("got lucky with rand")
        return igcd(N, a)
    print("a= ", a)
    print("N= ", N)
    r = period_find(a, N)
    print("r= ", r)
    if r % 2 == 1:
        print("r is not even, begin again")
        shor(N)
    answer = (igcd(a**(r/2) - 1, N), igcd(a**(r/2) + 1, N))
    return answer
def shor ( N ) : a = random . randrange ( N - 2 ) + 2 if igcd ( N , a ) != 1 : print ( "got lucky with rand" ) return igcd ( N , a ) print ( "a= " , a ) print ( "N= " , N ) r = period_find ( a , N ) print ( "r= " , r ) if r % 2 == 1 : print ( "r is not even, begin again" ) shor ( N ) answer = ( igcd ( a ** ( r / 2 ) - 1 , N ) , igcd ( a ** ( r / 2 ) + 1 , N ) ) return answer