whileTrue: d = random_prime(d_bound, lbound=d_lower_bound) if gcd(d, phi) == 1: e = inverse_mod(d, phi) if gcd(e, phi) == 1: break
print(f'n = {n}') print(f'e = {e}')
flag2 = pad(flag[len(flag)//2:], n_bits//8-1) m = bytes_to_long(flag2) c = pow(m, e, n) print(f'c = {c}')
""" n = 12779292788328507635646485236446323990578456114967808016182263578178494180795370424798860493650480053570371250811905773960481750940458827979861184722353108227092212225595979824252209841697659509529606215126716440565931530812981595774746754816326511322383070955072647153550727568166534351477967896890021106177 e = 9127521457923354456069487334973053064242751338553190692058159575640567634725596267894601092335626785885309669456842153792617210853891969129983736241476545935575261789952791385304618176639748270574246664480305757268659559315780221543289523307886165842999070576207133912422055150609884199685294091097607124409 c = 4715199541938838482829660474842815637758774748907642018610952495675409399919781649074418880398481916563366285817131200590553788510331744823499159289515632966376454919605434679417642103846284370991583023683038608112090557964515005763676931627459252593722505464252259469202165279234233266578704442372964772018 """
from Crypto.Util.number import * from Crypto.Util.Padding import pad import gmpy2
n = 12779292788328507635646485236446323990578456114967808016182263578178494180795370424798860493650480053570371250811905773960481750940458827979861184722353108227092212225595979824252209841697659509529606215126716440565931530812981595774746754816326511322383070955072647153550727568166534351477967896890021106177 c = 4715199541938838482829660474842815637758774748907642018610952495675409399919781649074418880398481916563366285817131200590553788510331744823499159289515632966376454919605434679417642103846284370991583023683038608112090557964515005763676931627459252593722505464252259469202165279234233266578704442372964772018 e = 9127521457923354456069487334973053064242751338553190692058159575640567634725596267894601092335626785885309669456842153792617210853891969129983736241476545935575261789952791385304618176639748270574246664480305757268659559315780221543289523307886165842999070576207133912422055150609884199685294091097607124409
n_bits = 1024 n_ = n >> (1024-428) # print(gmpy2.iroot(n_,2))
for i inrange(2**(511-213)): p = p + 1 if n % p == 0: print(i) q = n // p phi = (p-1)*(q-1) d = gmpy2.invert(e,phi) m = pow(c,d,n) flag2 = long_to_bytes(int(m)) flag = b'DASCTF{9a697216-6900-4' + flag2 print(flag) break # DASCTF{9a697216-6900-4a72-92e1-e3eefd98794f}
t = gmpy2.gcd(e1,e2) s,x,y = gmpy2.gcdext(e1,e2) if t == 1: m = (pow(c1,x,n)*pow(c2,y,n)) % n print(long_to_bytes(m)) else: for k inrange(1000): m = gmpy2.iroot((pow(c1,x,n)*pow(c2,y,n)%n + k*n),t) if m[1]: print(long_to_bytes(m[0])) break else: k += 1 # DASCTF{afd2eabdb2be11eda3a094085339ce84}
逆向工程
1
8eeb2dfb89f4b617abf9b6ac7bae3ee2777e85ec7e85a85a
出题人非碳基生物
先转byte,再base64加密
确认一下,你没有看错,就是base64加密,原来逆向工程指的是这个啊
exp:
1 2 3 4 5 6 7 8 9 10
from Crypto.Util.number import * import base64
c = "8eeb2dfb89f4b617abf9b6ac7bae3ee2777e85ec7e85a85a" c1 = long_to_bytes(int(c,16)) print(c1)
flag = b"DASCTF{" + base64.b64encode(c1) + b'}' print(flag) # DASCTF{just+4n0ther+base64+4nd+hex+haha}