#!/usr/bin/env python3 from Crypto.Util.number import *
with open('flag', 'rb') as f: flag = int.from_bytes(f.read(), 'big')
defgenkeys(): e = 65537 whileTrue: p, q = getPrime(512), getPrime(512) n, phi = p * q, (p - 1) * (q - 1) if GCD(e, phi) == 1: d = inverse(e, phi) return n, e, d
#!/usr/bin/env python3 from Crypto.Util.number import *
with open('flag', 'rb') as f: flag = int.from_bytes(f.read(), 'big')
defgenkeys(): e = 65537 whileTrue: p, q = getPrime(512), getPrime(512) n, phi = p * q, (p - 1) * (q - 1) if GCD(e, phi) == 1: d = inverse(e, phi) return n, e, d
from pwn import * from binascii import a2b_hex import decimal from Crypto.Util.number import *
deflsbOracle(c): r.recv() r.sendline("2") r.recvuntil("c = ") r.sendline(str(c)) m = r.recvline().strip()[3:] print("m: "+m) m = int(m) return m
defrevealFlag(c,n): k = n.bit_length() #二进制长度数,这里是1024 decimal.getcontext().prec = k #设定小数点精度 low = decimal.Decimal(0) high = decimal.Decimal(n) for i in range(k): plaintext = (low + high) / 2 state = lsbOracle(c) ifnot state: # state = 0 high = plaintext #0<high<n/2 else: low = plaintext c = (c * pow(2,e,n)) % n print i,state,int(high-low) return int(high)
if __name__ == '__main__': r = remote("127.0.0.1",1337) e = 65537 r.recv() r.sendline("1") c = r.recvline().strip()[3:] print("c: "+c) c = int(c) n = r.recvline().strip()[3:] print("n: "+n) n = int(n) res = revealFlag((c * pow(2,e,n)) % n, n) #res = 1624569960321307593137113337496607296102769342145048575242 print res res_hex = hex(res) #print res_hex print a2b_hex(res_hex[2:]) #一种方式打印flag print long_to_bytes(res) #另一种方式打印flag
from pwn import * import decimal from Crypto.Util.number import * from Crypto.PublicKey import RSA
deflsbOracle(c): r.recv() r.sendline("2") r.recvuntil("c = ") r.sendline(str(c)) m = r.recvline().strip()[3:] print("m: "+m) m = int(m) return m
if __name__ == '__main__': r = remote("127.0.0.1",1337) e = 65537 r.recv() r.sendline("1") c = r.recvline().strip()[3:] print("c: "+c) c = int(c) n = r.recvline().strip()[3:] print("n: "+n) n = int(n) a = 0 plaintext = 0 i = 0 f = 0 whileTrue: #for i in range(0,400): inv = inverse(3,n) # pow(3,-1) c1 = (c * pow(inv,e*i,n)) % n p = lsbOracle(c1) print p aa = (p - (a*inv) % n) % 3 print aa print"****" + str(i) if aa == 0: f += 1 if f == 20: break else: f = 0 a = a*inv + aa plaintext = 3**i*aa + plaintext print long_to_bytes(plaintext) i += 1 '''content = long_to_bytes(plaintext) if "BAMBOOFOX" in content: break''' print long_to_bytes(plaintext)