from random import randint

def nwd(a,n):
    A = n 
    B = a
    U = 0 
    V = 1
    while B !=0 :
        q = A/B 
        x1 = B
        x2 = A - q * B
        A = x1
        B = x2
        x1 = V
        x2 = U - q * V
        U = x1
        V = x2

    d = A
    u = U
    v = (d -a * u) // n

    return u,v,d

def inverseD(b,n):
    u,v,d = nwd(b,n)
    return d

def getST(n: int):
    d = n
    s = 0
    while True:
        if d % 2 == 0:
            d = d // 2
            s = s + 1
        else:
            break
    return s,d

def power(x, k, n) -> int:
    resultBin = bin(k)[2:]
    tabBin = list(reversed(resultBin))
    y = 1
    i = len(tabBin) - 1
    while (i >= 0 ):
        y = (y**2) % n
        if(tabBin[i] == '1'):
            y = (y * x) % n 
        i = i - 1
    return y 

def faktoryzacja(n,d,e):
    k = e * d - 1
    s,t = getST(k)
    while True:
        a = randint(1,n)
        
        if (inverseD(a,n) > 1):
            return a
        
        v = power(a,t,n)

        if (v % n == 1):
            return 0
        
        while ( v % n != 1 ):
            v0 = v % n
            v = power(v,2,n)
        
        if (v % n == -1):
            return 0
        else:
            result = inverseD(v0+1,n)
            result2 = n // result
        return result,result2

[encoded data, 7364 characters]

faktoryzacja(n,d,e)