zer0pts CTF 2022
Writeups: https://hackmd.io/@ptr-yudai/rJgjygUM9
The program implements Oblivisous Transfer by RSA. We can get either or . Our purpose is to get .
By sending such that , the stands.
Because and . ( is odd value)
Thus, where , stands.
Additionaly, the LSB of is always fixed because is consistent. Hence we can assume the parity of and find without modulo under the assumption. If the parity of is different from our assumption, we can get by adding to . Otherwise . Because is odd value.
Now we have . Can we determine uniquely?
Appearently no. But for now, we know and are different in every connection while is consistent. So considering about collecting some cases of pair.
For now, the problem is turned into to find from some .
Therefore, if the following problem is solved, secret
has been recovered.
Statement:
Generate an integer sequence from a random integer of bits and an integer sequence of random bits. Recover from the integer sequence .
Constraints:
First, let us make an observation about the generated number . From the facts about addition, the following formula transformation holds.
Here, the XOR in the part can be taken as inverting the bit extracted by &. So it should be the same if all the bits are inverted first and then extracted. Let us denote the bit inversion of as , then the following holds.
The equation transformation regarding bit inversion is a bit cumbersome, but it is no problem to think of it as the one's complement in a sufficiently large finite number of bits. In this case, since bits, we can write the following using .
This equation can be interpreted as a script like the following.
Now consider the probability that the most significant bit of is equal to the most significant bit of . It turns out that this is 1 if and the most significant bit are equal, and 1/2 if they are not ((symmetry makes it clear)). Since the most significant bit is always smaller when they are not equal, we can find the most significant bit of from the sequence with probability more than by taking the largest most significant bit. Next, subtract the most significant bit from and take its absolute value. Then we have the same problem for the second bit from the top.
Thus, we found that by repeating this process, we can find with probability greater than . The script will be as follows.