1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| from Crypto.Util.number import * import sys
def HGCD(a, b): if 2 * b.degree() <= a.degree() or a.degree() == 1: return 1, 0, 0, 1 m = a.degree() // 2 a_top, a_bot = a.quo_rem(x^m) b_top, b_bot = b.quo_rem(x^m) R00, R01, R10, R11 = HGCD(a_top, b_top) c = R00 * a + R01 * b d = R10 * a + R11 * b q, e = c.quo_rem(d) d_top, d_bot = d.quo_rem(x^(m // 2)) e_top, e_bot = e.quo_rem(x^(m // 2)) S00, S01, S10, S11 = HGCD(d_top, e_top) RET00 = S01 * R00 + (S00 - q * S01) * R10 RET01 = S01 * R01 + (S00 - q * S01) * R11 RET10 = S11 * R00 + (S10 - q * S11) * R10 RET11 = S11 * R01 + (S10 - q * S11) * R11 return RET00, RET01, RET10, RET11 def GCD(a, b): print(a.degree(), b.degree()) q, r = a.quo_rem(b) if r == 0: return b R00, R01, R10, R11 = HGCD(a, b) c = R00 * a + R01 * b d = R10 * a + R11 * b if d == 0: return c.monic() q, r = c.quo_rem(d) if r == 0: return d return GCD(d, r)
sys.setrecursionlimit(500000)
e = 65537 n1 = 96057998051371812919914259081675081604252517298501757815284793426110918357966765942391148507280051300098320736867050151134371603055535299365601258161010775195220785961631344762299227895001117209392625701969565546911778685726924433390650031008333418731518891577294501764604134694827909301545655417944252385457 n2 = 95181714079493329531165311913904927118650797513377627413903416782105479156418795803026947805144779310353978629552614854588095189968968837714554428210176704918400033966916106360194840969634589344847367250484955828002283022190696454537908315916133149984631966651777998417569331796811800254259365688365260226819 c1 = 43423259937720066480242410526037389734571893127158233205737545043602193683218952791597974839200703121553143890730144526413655108545977821189710879408898644701513344608064565504835818250834830946068290342466474835847253410119959543697202410717599632660251368457331495123509744140359426727527159405849222042904 c2 = 89537408314628349360681080619200657586241472538131163588783156955363783938404653920858723523923816459939025368445559319678708590708447372760960717580102364538146808058244182943711216634553435802209993315675850991445302288452001520355914988818746892371521355287514190070845238469510131978354461286857156484121
R.<x> = PolynomialRing(Zmod(n2)) f = x^e - c1 g = (2*n1 - x)^e - c2
res = GCD(f,g) print(long_to_bytes(int(-res.monic().coefficients()[0])))
|