Try   HackMD

TSG CTF 2020 Sweet like Apple Pie Writeup

c=sin(m) is given. We can immediately calculate
mmodπ
from
c
by using an appropriate series expansion of
arcsin
. Note that there are two corresponding values.

Now let

x=mmodπ and the calculation error be
δx
. We want to calculate

nπ+m=x+δx

Now if we calculate

|πxmn|,

|πxmn|=|x+δxmnxmn|=|δxn|

From the condition given in the challenge script,

|n|<2500/π. And if we experiment with the script we can tell that the precision of the function
sin(x)
in the script is about 150 digit in decimal, so we can evaluate
|δx|<2500
. So:

|πxmn|=|δxn|=|δxnn2|<1πn2<12n2

So, from Legendre's theorem in Diophantine approximations:

If

|αpq|<12q2,
pq
will be a principal approximation of
α
. [Ref]

xmn will be a principal approximation of
π
. That is, if we take some
pq
which is a principal approximation of
π
, we can observe

xmn=pqqx=pn+qm

Now let

N:=qx, and from

|Nq(x+δx)|=|qδx|<12

we can calculate that

round(q(x+δx))=N.

Nwo what we should do is to solve

n,m such that
N=pn+qm
, and this is achieved by

m=Nq1modp

Then you can try the above computation for all the principal approximation of

π, and the solution is one that satisfies
c=sin(m),m<2500
.