p = 10297529403524403127640670200603184608844065065952536889 a = 2 G = (8879931045098533901543131944615620692971716807984752065, 4106024239449946134453673742202491320614591684229547464) Q = (6784278627340957151283066249316785477882888190582875173, 6078603759966354224428976716568980670702790051879661797)
d = Integer((a * G[0]^3 + G[1]^3 + 1) * Integer(G[0] * G[1]).inverse_mod(p) % p) assert (a * Q[0]^3 + Q[1]^3 + 1) % p == (d * Q[0] * Q[1]) % p
x, y, z = QQ["x, y, z"].gens() eq = a * x^3 + y^3 + z^3 - d * x * y * z phi = EllipticCurve_from_cubic(eq) E = phi.codomain().change_ring(GF(p)) print(E) print(E.order())
F = GF(p) fx, fy, fz = map(lambda f: f.change_ring(F), phi.defining_polynomials()) phiP = lambda x, y, z=1: E(fx(x, y, z) / fz(x, y, z), fy(x, y, z) / fz(x, y, z)) EG = phiP(*G) EQ = phiP(*Q)
flag = discrete_log(EQ, EG, operation="+") print(flag)
from Crypto.Util.number import * print(long_to_bytes(flag)) # e@sy_cuRvL_c0o!
from Crypto.Util.number import * import math import re c = 356435791209686635044593929546092486613929446770721636839137 p = 898278915648707936019913202333 q = 814090608763917394723955024893 n = p * q e = 65537
# the idea is that our retrieved m is in fact equivalent to the original m mod n # so we add multiples of n to retrieve the flag # but this is inefficient so we have to narrow it down using format # The flag ends with }, so 7D = 125 mod 256 d = pow(e, -1, math.lcm(p-1, q-1)) m = pow(c, d, n) m = int(m) while m % 256 != 125: m += n jump = n * 256 # the flag starts with bcactf{ # we essentially want to try one possible flag length at a time # by jumping up to the next one starting with bcactf # 0 is the smallest char (by code) that can appear in the flag target = b'DASCTF{' + b'0'*math.floor(math.log(m, 256)-7) md = long_to_bytes(m) while re.fullmatch(b'[0-9a-zA-Z_{}]+', md) == None: if md[0:7] == b'DASCTF{': m += jump # print(md) else: m += jump * math.ceil((bytes_to_long(target) - m)/jump) target += b'0' # print(math.log(m,2)) md = long_to_bytes(m) print(md)
n = 18770575776346636857117989716700159556553308603827318013591587255198383129370907809760732011993542700529211200756354110539398800399971400004000898098091275284235225898698802555566416862975758535452624647017057286675078425814784682675012671384340267087604803050995107534481069279281213277371234272710195280647747033302773076094600917583038429969629948198841325080329081838681126456119415461246986745162687569680825296434756908111148165787768172000131704615314046005916223370429567142992192702888820837032850104701948658736010527261246199512595520995042205818856177310544178940343722756848658912946025299687434514029951 c = 2587907790257921446754254335909686808394701314827194535473852919883847207482301560195700622542784316421967768148156146355099210400053281966782598551680260513547233270646414440776109941248869185612357797869860293880114609649325409637239631730174236109860697072051436591823617268725493768867776466173052640366393488873505207198770497373345116165334779381031712832136682178364090547875479645094274237460342318587832274304777193468833278816459344132231018703578274192000016560653148923056635076144189403004763127515475672112627790796376564776321840115465990308933303392198690356639928538984862967102082126458529748355566
# yafu p = 137005750887861042579675520137044512945598822783534629619239107541807615882572096858257909592145785126427095471870315367525847725823941391135851384962433640952546093687945848986528958373691860995753297871619638780075391669495117388905134584566094832853663864356912013900594295175075123578366393694884648557429 q = 137005750887861042579675520137044512945598822783534629619239107541807615882572096858257909592145785126427095471870315367525847725823941391135851384962433640952546093687945848986528958373691860995753297871619638780075391669495117388905134584566094832853663864356912013900594295175075123578366393694884648557219 assert p * q == n
defdecode_e(e): if e > 1: mul = 1 for i inrange(1, e): mul *= i if e - mul % e - 1 == 0: mulmod = mul % e - e else: mulmod = mul % e return mulmod + decode_e(e - 1) else: return0
defgao(n): assert n > 4 res = 0 for i inrange(5, n+1): if is_pseudoprime(i): res += 1 return -res
''' for i in range(5, 256): #assert decode_e(i) == gao(i) print(decode_e(i), prime_pi(i) - 2) '''
#e = Integer(abs(gao(703440151))) e = Integer(prime_pi(703440151) - 2) phi = (p-1) * (q-1) d = e.inverse_mod(phi)
m = pow(c, d, n) flag = bytes.fromhex(hex(m)[2:]) print(flag)