from Crypto.Util.number import * from secret import flag
p = getPrime(512) q = getPrime(512) n = p * q d = getPrime(299) e = inverse(d,(p-1)*(q-1)) m = bytes_to_long(flag) c = pow(m,e,n) hint1 = p >> (512-70) hint2 = q >> (512-70)
n = 102986063343828181691017061322961752231482650979117614592328540336319559999419987417702811972323418742113520151888629472567603955481992514927285801019993715247868027388036294100323295206260750653997980051233409135844852567338000284382992259587294344858347675971990058869658603742150067210112531948312675289517 e = 94332227188033251470419190704216678578924281824166571884737945076375866824249376355159909654478713223003101525619990336866998705667204377661713202948952171655143192075943578946573888576484746209261469970149381872389631389369537155026693263975338398261567274837717090694055171425503933824240291370948820767571 c = 84437879482958388121051989985943610317985560730924629180079819055930253313815835352959163593476985818700482462237552702247843204909498317690512763185777267125647066466604295815291929505489611365030554559376546705541333232100362213541469056985011640358767366350305910694542127597286950765375388740496062563517 hint1 = 737132842226563731129 hint2 = 1083219649182192077965
n = 102986063343828181691017061322961752231482650979117614592328540336319559999419987417702811972323418742113520151888629472567603955481992514927285801019993715247868027388036294100323295206260750653997980051233409135844852567338000284382992259587294344858347675971990058869658603742150067210112531948312675289517 e = 94332227188033251470419190704216678578924281824166571884737945076375866824249376355159909654478713223003101525619990336866998705667204377661713202948952171655143192075943578946573888576484746209261469970149381872389631389369537155026693263975338398261567274837717090694055171425503933824240291370948820767571 c = 84437879482958388121051989985943610317985560730924629180079819055930253313815835352959163593476985818700482462237552702247843204909498317690512763185777267125647066466604295815291929505489611365030554559376546705541333232100362213541469056985011640358767366350305910694542127597286950765375388740496062563517 hint1 = 737132842226563731129 hint2 = 1083219649182192077965
defsmall_roots(f, bounds, m=1, d=None): ifnot d: d = f.degree()
ifisinstance(f, Polynomial): x, = polygens(f.base_ring(), f.variable_name(), 1) f = f(x)
R = f.base_ring() N = R.cardinality() f /= f.coefficients().pop(0) f = f.change_ring(ZZ)
G = Sequence([], f.parent()) for i inrange(m+1): base = N^(m-i) * f^i for shifts in itertools.product(range(d), repeat=f.nvariables()): g = base * prod(map(power, f.variables(), shifts)) G.append(g)
factors = [monomial(*bounds) for monomial in monomials] for i, factor inenumerate(factors): B.rescale_col(i, factor)
B = B.dense_matrix().LLL()
B = B.change_ring(QQ) for i, factor inenumerate(factors): B.rescale_col(i, 1/factor)
H = Sequence([], f.parent().change_ring(QQ)) for h infilter(None, B*monomials): H.append(h) I = H.ideal() if I.dimension() == -1: H.pop() elif I.dimension() == 0: roots = [] for root in I.variety(ring=ZZ): root = tuple(R(root[var]) for var in f.variables()) roots.append(root) return roots
p = 12301968561617489464815050947766830293114620865458225788140524305916037841132536540947500706435198484135356575495711684836395758643449054231737718416631877 q = 8371510854380475760171492071954527819328254117130991402450088629039514773535702565532229588993733813828621162046243254767866899527502246818456584983541321 n = 102986063343828181691017061322961752231482650979117614592328540336319559999419987417702811972323418742113520151888629472567603955481992514927285801019993715247868027388036294100323295206260750653997980051233409135844852567338000284382992259587294344858347675971990058869658603742150067210112531948312675289517 e = 94332227188033251470419190704216678578924281824166571884737945076375866824249376355159909654478713223003101525619990336866998705667204377661713202948952171655143192075943578946573888576484746209261469970149381872389631389369537155026693263975338398261567274837717090694055171425503933824240291370948820767571 c = 84437879482958388121051989985943610317985560730924629180079819055930253313815835352959163593476985818700482462237552702247843204909498317690512763185777267125647066466604295815291929505489611365030554559376546705541333232100362213541469056985011640358767366350305910694542127597286950765375388740496062563517
phi = (p-1)*(q-1) assert GCD(e,phi)==1 d = inverse(e,phi) m = pow(c, d, n) print(long_to_bytes(int(m)))
CRYPTO02
# coding: utf-8 #!/usr/bin/env python2
import gmpy2 import random import binascii from hashlib import sha256 from sympy import nextprime from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Util.number import long_to_bytes from FLAG import flag #flag = 'wdflag{123}'
p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f a = 0 b = 7 xG = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 yG = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 G = (xG, yG) n = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 h = 1 zero = (0,0)
dA = nextprime(random.randint(0, n))
if dA > n: print("warning!!")
defaddition(t1, t2): if t1 == zero: return t2 if t2 == zero: return t2 (m1, n1) = t1 (m2, n2) = t2 if m1 == m2: if n1 == 0or n1 != n2: return zero else: k = (3 * m1 * m1 + a) % p * gmpy2.invert(2 * n1 , p) % p else: k = (n2 - n1 + p) % p * gmpy2.invert((m2 - m1 + p) % p, p) % p m3 = (k * k % p - m1 - m2 + p * 2) % p n3 = (k * (m1 - m3) % p - n1 + p) % p return (int(m3),int(n3))
defmultiplication(x, k): ans = zero t = 1 while(t <= k): if (k &t )>0: ans = addition(ans, x) x = addition(x, x) t <<= 1 return ans
defgetrs(z, k): (xp, yp) = P r = xp s = (z + r * dA % n) % n * gmpy2.invert(k, n) % n return r,s
z1 = random.randint(0, p) z2 = random.randint(0, p) k = random.randint(0, n) P = multiplication(G, k) hA = multiplication(G, dA) r1, s1 = getrs(z1, k) r2, s2 = getrs(z2, k)