No Padding, No Problem (90)
RSA chosen-ciphertext attack (CCA)
Last updated
RSA chosen-ciphertext attack (CCA)
Last updated
from Crypto.Util.number import *
from pwn import *
from decimal import *
import re
getcontext().prec = 1000
conn = remote('mercury.picoctf.net', 30048)
raw_text = conn.recvuntil('Give me ciphertext to decrypt:').decode()
print(raw_text)
m = re.search(r"n: ([0-9]+)\ne: ([0-9]+)\nciphertext: ([0-9]+)", raw_text)
n = int(m[1])
e = int(m[2])
c = int(m[3])
to_decrypt = c * pow(2, e, n) % n
conn.send(str(to_decrypt) + '\r\n')
print("Sent:", to_decrypt)
result = conn.recvline().decode()
print(result)
m = re.search(r"([0-9]+)", result)
result = int(Decimal(m[1]) / 2)
print(hex(result))
print('Result:', long_to_bytes(result))