n = 0x1FFC7DC6B9667B0DCD00D6AE92FB34ED0F3D84285364C73FBF6A572C9081931BE0B0610464152DE7E0468CA7452C738611656F1F9217A944E64CA2B3A89D889FFC06E6503CFEC3CCB491E9B6176EC468687BF4763C6591F89E750BF1E4F9D6855752C19DE4289D1A7CEA33B077BDCDA3C84F6F3762DC9D96D2853F94CC688B3C9D8E67386A147524A2B23B1092F0BE1AA286F2AA13AAFBA62604435ACBAA79F4E53DEA93AE8A22655287F4D2FA95269877991C57DA6FDEEB3D46270CD69B6BFA537BFD14C926CF39B94D0F06228313D21EC6BE2311F526E6515069DBB1B06FE3CF1F62C0962DA2BC98FA4808C201E4EFE7A252F9F823E710D6AD2FB974949751 c = 0x60160BFED79384048D0D46B807322E65C037FA90FAC9FD08B512A3931B6DCA2A745443A9B90DE2FA47AAF8A250287E34563E6B1A6761DC0CCB99CB9D67AE1C9F49699651EAFB71A74B097FC0DEF77CF287010F1E7BD614DCCFB411CDCCBB84C60830E515C05481769BD95E656D839337D430DB66ABCD3A869C6348616B78D06EB903F8ABD121C851696BD4CB2A1A40A07EEA17C4E33C6A1BEAFB79D881D595472AB6CE3C61D6D62C4EF6FA8903149435C844A3FAB9286D212DA72B2548F087E37105F4657D5A946AFD12B1822CEB99C3B407BB40E21163C1466D116D67C16A2A3A79E5CC9D1F6A1054D6BE6731E3CD19ABBD9E9B23309F87BFE51A822410A62
P.<x> = ZZ[]
t = 1 << 1024 whileTrue: f = x ^ 2 - t * x + n rs = f.roots() iflen(rs) > 0: p = rs[0][0] q = n // p assert p * q == n break t += 1 d = inverse_mod(65537, (p - 1) * (q - 1)) m = power_mod(c, d, n) print(long_to_bytes(m).decode()) # zer0pts{F3rm4t,y0ur_m3th0d_n0_l0ng3r_w0rks.y0u_4r3_f1r3d}
import os from random import randrange from Crypto.Util.number import bytes_to_long, long_to_bytes, getStrongPrime from Crypto.Util.Padding import pad from fastecdsa.curve import Curve
defxgcd(a, b): x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0
defgen(): whileTrue: p = getStrongPrime(512) if p % 4 == 3: break whileTrue: q = getStrongPrime(512) if q % 4 == 3: break n = p * q a = randrange(n) b = randrange(n)
whileTrue: x = randrange(n) y2 = (x**3 + a*x + b) % n assert y2 % n == (x**3 + a*x + b) % n ifpow(y2, (p-1)//2, p) == 1andpow(y2, (q-1)//2, q) == 1: yp, yq = pow(y2, (p + 1) // 4, p), pow(y2, (q + 1) // 4, q) _, s, t = xgcd(p, q) y = (s*p*yq + t*q*yp) % n break return Curve(None, n, a, b, None, x, y)
defencrypt(m, G): blocks = [m[16*i:16*(i+1)] for i inrange(len(m) // 16)] c = [] for i inrange(len(blocks)//2): G = G + G c.append(G.x ^ bytes_to_long(blocks[2*i])) c.append(G.y ^ bytes_to_long(blocks[2*i+1])) return c
defdecrypt(c, G): m = b'' for i inrange(len(c) // 2): G = G + G m += long_to_bytes(G.x ^ c[2*i]) m += long_to_bytes(G.y ^ c[2*i+1]) return m
flag = pad(os.environ.get("FLAG", "fakeflag{sumomomomomomomomonouchi_sumomo_mo_momo_mo_momo_no_uchi}").encode(), 32) C = gen() c = encrypt(flag, C.G) assert decrypt(c, C.G) == flag
n = 144119247523820514307319742558945817289524321678464785828165262389987364282241677120346992289602773032781170623185859522408681068717004227361637296377314973988883717763449514502353544535632434189976809320943402560377421207936239458384129077990667822889168041784489265932700188699685494064706711885776064499497 a = 83982245487363010227377287615815704138676734572052340268107937333404040064487258387610318909300475704005267406361509228314981566916144028418544919408625857597243933586742790305821574823017061268314657578742703998273111267249007415214833152992932175602495617018238154444547422725699672732735594492967242602718 b = 102854241650706614574910858961148621902783569513613650939938174283440416794379436560775021794677794290971284767314108620894847399989166711219489947662922391647064573171363714323032220660223765035347554282052095512011142748460282601639626032525448005114625186640435086840602281790716023653081557628791656792754 c = [ 105112301098281496097034027523577403453326764144228787624401074405541577932642530851395484380691290162552636478481380927941044566041120344238783491322553291628678134801814105484196704974017218455216419335693731277825573231392222665423245586612395848380318111988284920983149197374154699808776545479724047776709, 119931822446994265076022490333904239240145849067899601686086810952135061724293475540637951596476598377673280140779509869539582077226280886787012312965074972316057414014195571814522208145587153069696640304889800585974357119323578638404957302760851214606619517664508954712497284900223656294050022339709410514520, 77449803463514047535477961978015960018035778347793833401263588747978475501148536780819549296447786417024775899457091074251167349568353877838782428368954481576827862607179873977973077737374411980559467128298050283927229354740670622117284854556777626729609958202274963553796799701913426256413699327094959918436, 19881898638980767541769585302774976337079209934548061143259050559139791898245439933411471322660256972236103364955342341822881304403603105610433373205174678091884754857958259183427619764249723943787639988589593508171175819610469625589807019978156747244656206732357606116993349990555417285468500357366492529137, ]
load("coppersmith.sage") P.<xx,yy> = Zmod(n)[] x = c[0] + xx y = c[1] + yy f = y ^ 2 - (x ^ 3 + a * x + b)
xx, yy = small_roots(f, (2 ^ 128, 2 ^ 128))[0] x = (c[0] + xx) % n y = (c[1] + yy) % n assert (y ^ 2) % n == (x ^ 3 + a * x + b) % n print(x, y) # 2G
from Crypto.Util.number import long_to_bytes from fastecdsa.curve import Curve
defdecrypt(c, G): m = b"" for i inrange(len(c) // 2): m += long_to_bytes(G.x ^ c[2 * i]) m += long_to_bytes(G.y ^ c[2 * i + 1]) G = G + G return m
n = 144119247523820514307319742558945817289524321678464785828165262389987364282241677120346992289602773032781170623185859522408681068717004227361637296377314973988883717763449514502353544535632434189976809320943402560377421207936239458384129077990667822889168041784489265932700188699685494064706711885776064499497 a = 83982245487363010227377287615815704138676734572052340268107937333404040064487258387610318909300475704005267406361509228314981566916144028418544919408625857597243933586742790305821574823017061268314657578742703998273111267249007415214833152992932175602495617018238154444547422725699672732735594492967242602718 b = 102854241650706614574910858961148621902783569513613650939938174283440416794379436560775021794677794290971284767314108620894847399989166711219489947662922391647064573171363714323032220660223765035347554282052095512011142748460282601639626032525448005114625186640435086840602281790716023653081557628791656792754 c = [ 105112301098281496097034027523577403453326764144228787624401074405541577932642530851395484380691290162552636478481380927941044566041120344238783491322553291628678134801814105484196704974017218455216419335693731277825573231392222665423245586612395848380318111988284920983149197374154699808776545479724047776709, 119931822446994265076022490333904239240145849067899601686086810952135061724293475540637951596476598377673280140779509869539582077226280886787012312965074972316057414014195571814522208145587153069696640304889800585974357119323578638404957302760851214606619517664508954712497284900223656294050022339709410514520, 77449803463514047535477961978015960018035778347793833401263588747978475501148536780819549296447786417024775899457091074251167349568353877838782428368954481576827862607179873977973077737374411980559467128298050283927229354740670622117284854556777626729609958202274963553796799701913426256413699327094959918436, 19881898638980767541769585302774976337079209934548061143259050559139791898245439933411471322660256972236103364955342341822881304403603105610433373205174678091884754857958259183427619764249723943787639988589593508171175819610469625589807019978156747244656206732357606116993349990555417285468500357366492529137, ]
gx = 105112301098281496097034027523577403453326764144228787624401074405541577932642530851395484380691290162552636478481380927941044566041120344238783491322553291628678134801814105484196704974017218455216419335693731277825573231392222665423245586612395848380318111988284920983114163361424268999964406373744402729889 gy = 119931822446994265076022490333904239240145849067899601686086810952135061724293475540637951596476598377673280140779509869539582077226280886787012312965074972316057414014195571814522208145587153069696640304889800585974357119323578638404957302760851214606619517664508954712596897120285942097736344387658770086763 C = Curve(None, n, a, b, None, gx, gy) print(decrypt(c, C.G).decode().strip())
from random import randrange from Crypto.Util.number import inverse, long_to_bytes from Crypto.Cipher import AES from hashlib import sha256 import ast import os import signal
n = 256 p = 64141017538026690847507665744072764126523219720088055136531450296140542176327 a = 362 d = 1 q = 64141017538026690847507665744072764126693080268699847241685146737444135961328 c = 4 gx = 36618472676058339844598776789780822613436028043068802628412384818014817277300 gy = 9970247780441607122227596517855249476220082109552017755637818559816971965596
defxor(xs, ys): returnbytes(x^y for x, y inzip(xs, ys))
defmul(x, P): Q = (0, 1) x = x % q while x > 0: if x % 2 == 1: Q = add(Q, P) P = add(P, P) x = x >> 1 return Q
defto_bytes(P): x, y = P returnint(x).to_bytes(n // 8, "big") + int(y).to_bytes(n // 8, "big")
deffrom_bytes(b): x = int.from_bytes(b[:32], "big") y = int.from_bytes(b[32:], "big") return x, y
n = 256 p = 64141017538026690847507665744072764126523219720088055136531450296140542176327 a = 362 d = 1 q = 64141017538026690847507665744072764126693080268699847241685146737444135961328 c = 4
R[:, :nr] *= 2 ^ 10 print("start LLL", R.dimensions()) # R = R.BKZ(algorithm="NTL") R = R.LLL()
print("=" * 10)
goodvecs = [] for row in R: ifany([x != 0for x in row[:nr]]): continue ifall(-1 <= x <= 1for x in row): goodvecs.append(row[nr:]) print(row[nr:]) print("gvecs", len(goodvecs))
defis_good(v): ifall([x == 0for x in v]): returnNone ifall([0 <= x <= 1for x in v]): returntuple(v) ifall([-1 <= x <= 0for x in v]): returntuple(-v)
print("find 01 basis")
from itertools import product from tqdm import tqdm
avecs = set() for v in goodvecs: ifall(0 <= x <= 1for x in v): avecs.add(tuple(v)) bestvec = v print(len(avecs)) for v1 in tqdm(goodvecs): for v2 in goodvecs: for coef in product([-1, 0, 1], repeat=3): vv = coef[0] * v1 + coef[1] * v2 + coef[2] * bestvec ifany([x < 0for x in vv]): vv = -vv ifall([0 <= x <= 1for x in vv]) andsum(vv) != 0: avecs.add(tuple(vv)) iflen(avecs) == n: break
print(len(avecs)) avecs = list(avecs) AT = matrix(ZZ, avecs).T x = AT.change_ring(Zmod(p)).solve_right(vector(h)).change_ring(ZZ) print(x)
from Crypto.Util.number import *
for row in AT.T: bits = "".join(map(str, row))[::-1] m = int(bits, 2) f = long_to_bytes(m) ifb"zer0pts"in f: print(f)
defMathHash(m): hashval = 0 for i inrange(len(m) - 7): c = struct.unpack("<Q", m[i : i + 8])[0] t = math.tan(c * math.pi / (1 << 64)) hashval ^= struct.unpack("<Q", struct.pack("<d", t))[0] return hashval
defkhash(m, k): if m == b"FLAG": return get_hash(k) for i, c inenumerate(k): m = m[:i] + bytes([(m[i] + k[i]) % 0x100]) + m[i + 1 :] return MathHash(m)
defdiff(m, kpfx, wrapper=lambda x: x): hashes = [] for x in wrapper(range(256)): hashes.append(khash(m, kpfx + bytes([x]))) return [x ^ y for x in hashes for y in hashes]
defsim(x, y): l = len([1for a, b inzip(x, y) if a == b]) return l / len(x)
known = b"zer0pts{s1gn+|3xp^|fr4c" whilenot known.endswith(b'}'): kpfx = (len(known) - 6) * b"\xff"# 6 may need to be adjusted dflag = diff(b"FLAG", kpfx, wrapper=tqdm) good = [] for x inrange(0x20, 0x7F): d = diff(known + bytes([x]), kpfx) s = sim(d, dflag) if s > 0.9: good.append((bytes([x]), s)) good.sort(key=lambda t: t[1], reverse=True) good = [x for x, y in good] iflen(good) == 1: known += good[0] else: print(good) known += good[int(input("which: "))] print(known)