defcomplex_pow(c, exp, n): result = Complex(1, 0) while exp > 0: if exp & 1: result = result * c result.re = result.re % n result.im = result.im % n c = c * c c.re = c.re % n c.im = c.im % n exp >>= 1 return result
flag = flag.strip(b"XYCTF{").strip(b"}") p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027 g = Complex(3, 7) x = bytes_to_long(flag) print(complex_pow(g, x, p)) # 5699996596230726507553778181714315375600519769517892864468100565238657988087817 + 198037503897625840198829901785272602849546728822078622977599179234202360717671908i
p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027 re = 5699996596230726507553778181714315375600519769517892864468100565238657988087817 im = 198037503897625840198829901785272602849546728822078622977599179234202360717671908 Zp = Zmod(p) g = Zp(3^2 + 7^2) y = Zp(re ^ 2 + im ^ 2) print("g =", g) print("y =", y) print("g ^ x = y") # g = 58 # y = 440338354863477089588878295048682566041450520053821907911657559153659930236947297 # g ^ x = y
最后扔给discrete_log解之:
1 2 3 4 5 6 7 8 9 10 11
from Crypto.Util.number import * p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027 Zp = Zmod(p) g = Zp(58) y = Zp(440338354863477089588878295048682566041450520053821907911657559153659930236947297) # g ^ x = y x = discrete_log(y,g) print("x =",x) print(long_to_bytes(x)) # x = 11043386733210093783917591062922767739440701223101839768310052590794700044066655 # b'___c0mp13x_d1p_15_3@5y_f0r_y0u___'