Challenges › Cryptography

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:

client.py opens one connection, reads n, e, c and the message length, and gives you Oracle.parity(x) for your scripts.

Your task.

  1. Multiply c by 2^e mod n. The new ciphertext decrypts to 2m mod n.
  2. Use each parity reply to halve the interval that holds m. Start with 0 <= m < n.
  3. After about 1024 queries, one integer is left. Check it with pow(m, e, n) == c.
  4. Convert m to 24 bytes, big-endian.

The message is the flag.

Tags: learn

Try next