from banner import *
from utilis import egcd,Convert
banner()
"""
n = 121785996773018308653850214729611957957750585856946607620398279656647965006857599756926384863459274369411103073349913717154710735727786240206066327436155758154142877120260776520601315370480059127244029804523614658953301573686851312721445206131147094674807765817210890772194336025491364961932882951123597124291
e2 = 343223
c2 = 99993713982446651581396992055360571139557381122865583938229634474666415937105325664345678113405954865343401854091338680448775405253508255042453184099961570780032181898606546389573694481401653361757628850127420072609555997892925890632116852740542002226555293049123266123721696951805937683483979653786235824108
e1 = 65537
c1 = 5050983197907648139720782448847677677343236446273586870502111273113384857588837608900494692102715861436825279596563904392832518247929761994240007673498974877828278590361242528762459283022987952424770766975922016521475963712698089809426428406068793291250622593222599407825968002220906973019105007856539702124
"""
try:
    import gmpy2
    from Crypto.Util.number import GCD

    def neg_pow(a, b, n):
        assert b < 0
        assert GCD(a, n) == 1
        res = int(gmpy2.invert(a, n))
        return pow(res, b*(-1), n)

    def common_modulus(e1, e2, n, c1, c2):
        g, a, b = egcd(e1, e2)
        c1 = neg_pow(c1, a, n) if a < 0 else pow(c1, a, n)
        c2 = neg_pow(c2, b, n) if b < 0 else pow(c2, b, n)
        ct = c1*c2 % n
        return int(gmpy2.iroot(ct, g)[0])
    
    c1 = int(input(">>> c1 = "))
    c2 = int(input(">>> c2 = "))
    e1 = int(input(">>> e1 = "))
    e2 = int(input(">>> e2 = "))
    n = int(input(">>> n = "))
  
    Convert(common_modulus(e1, e2, n, c1, c2))
except ImportError:
    slowprint("\n[-] Module Not Setup")
except ValueError:
    slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number")
except AssertionError:
    slowprint("\n[-] Wrong Data")
except KeyboardInterrupt:
    exit()
except:
    slowprint("\n[-] False Attack !")
