# %% [cell 8]
def myGCDIter(a,b):
    while b!=0:
        (a,b)=(b,a%b)
    return a

def extendedGCD(a,b):
    coef_2=(1,0)
    coef_1=(0,1)
    while b!=0:
        quotient=a//b
        (a,b)=(b,a%b)
        (coef_2,coef_1)=(coef_1,(coef_2[0]-quotient*coef_1[0],coef_2[1]-quotient*coef_1[1]))
    return a,coef_2[0],coef_2[1]

def inverseMod(a,m):
    gcd,inv,_=extendedGCD(a,m)
    if gcd != 1:
        raise Exception("Error, "+str(a)+" does not admit an inverse mod "+str(m))
    return inv%m

# %% [cell 11]
def sqm(a, e, m):


# %% [cell 13]
c1=18681427692158875519487088075483659952350784095426850535886777025764383119115214958422688170629212939425578696612104065278836818480205439611172533343162586565318046086821649841855655529786476912936117
c2=23262524066749752930003794793282025892156162339903512977981352192237243527808339996497055361739127886746797334866642423823838668793093810257339868397178981443559849998387464783404753032562620423782819

sqm(c1, c1, c2)

# %% [cell 15]


# %% [cell 18]
p=879444170374861669641134196218346212695898251128878861274462696397360027254709043134636220593750949647657696083593011526569499231402671759015715247847100292170454549945387184247594207004818786761105412070559714186375611091845523065678013356121887671718894703109758066601977029635298290603841128648803
q=498123355539734090651342024511099831516304715462262346470827576945203575116701551738041914223749202101027640044384914081312728700908681008628987214128029359450401447589262841875627065956937931557006312756303050952146176840242929855061267653489429686714147273857523203781398260195342718507985441066291

# %% [cell 20]


# %% [cell 22]


# %% [cell 24]


# %% [cell 26]


# %% [cell 28]


# %% [cell 31]


# %% [cell 33]


# %% [cell 36]

