for i inrange(2): r.recvuntil("mask:") r.sendline('0') r.recvuntil("guess:") r.sendline('18446744073709551615') back = r.recvline(False) print(turn,back)
deftalk(x): r.recvuntil("give me a number:\n") r.sendline(str(x)) r.recvuntil("done: ") returnint(r.recvline(False).strip().decode())
passpow() print('Successfully pass the pow!')
r.recvuntil("n: ") n = int(r.recvline(False).strip().decode()) print(n)
a = talk(0) b = talk(0) delta = b+n-a
q = gcd(delta,n) assert q != 1 p = n // q assert p * q == n
iv = talk(q)
phi = (p-1) * (q-1) elist = [] for i inrange(1,8): elist.append(pow(i,pow(i,i,phi),phi))
flag = '001010100100001101010'
while (len(flag)<120): delta = talk(0) - iv for i inrange(128): tmp = bin(i)[2:].rjust(7,'0') res = 0 for j inrange(len(tmp)): if(tmp[j] == '1'): res += pow(q,elist[j],n) res %= n if(delta%n == res): flag += bin(i)[2:].rjust(7,'0') print(bin(i)[2:].rjust(7,'0')) break
flag = flag[:120] print(flag) flag = long_to_bytes(int(flag,2)) print(flag)
little case
题目分为两部分,一个是little_trick,一个是real_trick
阅读代码后发现little_trick就是RSA的wiener attack,最后即可分解n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
from Crypto.Util.number import * from gmpy2 import *
c1 = 17653913822265292046140436077352027388518012934178497059850703004839268622175666123728756590505344279395546682262531546841391088108347695091027910544112830270722179480786859703225421972669021406495452107007154426730798752912163553332446929049057464612267870012438268458914652129391150217932076946886301294155031704279222594842585123671871118879574946424138391703308869753154497665630799300138651304835205755177940116680821142858923842124294529640719629497853598914963074656319325664210104788201957945801990296604585721820046391439235286951088086966253038989586737352467905401107613763487302070546247282406664431777475 p = pow(c1,d1,n1) + 1 n = 22346087036331379968192118389403047568445805414881948978518580277027027486284293415097623011228506968071753709256352246733181304513713003096615266613365080909760605498017330085960699607777361429562376124376340215426398797920168016137830563564636922257215066266075494625782943973857490781916694118187094786034792437781964601089843549995939887939410763350338658901108020658475956489391300528691289604149598720803012371765770928211044755626045817053870803040863722458554924076011151695567147976903053993914859714631837755435592006986598006207692599019026644753575853382810261910332197447386727419606073948645238377595719 q = n // p assert p * q == n
# About 3 seconds to run defAMM(o, r, q): g = GF(q) o = g(o) p = g(random.randint(1, q)) while p ^ ((q-1) // r) == 1: p = g(random.randint(1, q)) t = 0 s = q - 1 while s % r == 0: t += 1 s = s // r k = 1 while (k * s + 1) % r != 0: k += 1 alp = (k * s + 1) // r a = p ^ (r**(t-1) * s) b = o ^ (r*alp - 1) c = p ^ s h = 1 for i inrange(1, t): d = b ^ (r^(t-1-i)) if d == 1: j = 0 else: j = - discrete_log(d, a) b = b * (c^r)^j h = h * c^j c = c^r result = o^alp * h return result
start = time.time() print('Start') for mpp in mps: for mqq in mqs: solution = CRT_list([int(mpp), int(mqq)], [p, q]) if check(solution): print(solution) qwq.append(solution) print(time.time() - start)
print(qwq) end = time.time() print("{} s.".format(end - start)) # 1061.3823564052582 s. # b'*CTF{S0_Y0u_ARE_REA11Y_GOOd_At_Pla1_This}Ifyoumissthetrainimonyouwillknowthatiamgoneyoucanheartheflagfluwwwwwwwwww' # 5715792447162584004830995621288196364667316788985719423575200593843082226610550301623816157835166569193582787431644910982754181340491582409788340367828925355394884518044538804653367543125682677650052644197537897019515168750419392615178911318381369421233129629180441067485047