Ask the Parity Oracle
hard · 200 XP · machine with a lab · free · solves: 0
A test service holds a textbook RSA private key. It decrypts any ciphertext you send and tells you only whether the result is even or odd. You have the public key and one target ciphertext c in public.txt. The target message is a 24-byte string. It is encoded big-endian as the integer m, with m < n, and c = m^e mod n. There is no padding.
Start the lab. The service runs on host oracle, TCP port 9000.
Protocol. The service sends six banner lines when you connect: a help line, n = ..., e = ..., c = ..., message length = 24 bytes and the query count. Send one command per line:
parity <x>: x is a decimal integer with 0 <= x < n. The service computes x^d mod n and replies0when the result is even or1when it is odd.- Each connection allows 1100 parity queries. n has 1024 bits. After the reply to the last query, the service sends
error: query limit reachedand closes the connection. A new connection starts a new count with the same key and target. - A bad command gets one reply line that starts with
error:. It uses no query. A line longer than 1024 characters getserror: line too longand closes the connection.
client.py opens one connection, reads n, e, c and the message length, and gives you Oracle.parity(x) for your scripts.
Your task.
- Multiply c by 2^e mod n. The new ciphertext decrypts to 2m mod n.
- Use each parity reply to halve the interval that holds m. Start with 0 <= m < n.
- After about 1024 queries, one integer is left. Check it with pow(m, e, n) == c.
- Convert m to 24 bytes, big-endian.
The message is the flag.
Tags: learn
Try next
- Read the Vault's Timing (medium)
- Recover the Hidden Suffix (medium)
- Recover Plaintext with a Padding Oracle (medium)