# Decrypt RSA ciphertext with two middle bits leak

Given RSA public key (e.g. 1024 bits) and decryption oracle that outputs 2 middle bits of decrypted ciphertext (pow(ciphertext,d,n) >> (1024/2)) & 3, how can we decrypt whole message?

Question related to "Pinhole Attack" task from Tokyo Westerns/MMA ctf.

This appears to be homework, and so I won't tell your outright; I will give you a hint.

Suppose you compute:

$$c_1 = c \times 2^e \bmod n$$

How are the decryptions of $c$ and $c_1$ related?

Suppose we compute a long series of:

$$c_i = c \times (2^i)^e \bmod n$$

What does the middle two bits of $c_i$ tell us?

• foa. it's from competition, meaning not homework. I know about multiplicative property of RSA and how to decrypt message given LSB of plaintext. But still can't see what to do with middle bits (or, say, arbitrary at fixed location). – Gros Sep 8 '16 at 7:34

There is a good write up of this task from More Smoked Leet Chicken team.