cotan

A description of the challenge was also provided along with the source code. Please have a look at cotan.pdf.

Challenge files: cotan.pdf, cotan.py.

The challenge name refers to the fact that we’re somehow `emulating’ the cotangent function in a finite field

cotangent

In real numbers, this is effectively finding \(n\) given \(\cot\left(n\cot^{-1}(2)\right)=k\), however, the challenge is in \(\mb F_p\)

Consider how cotangent is related to the complex expressions:

\[\cot(x)=i\frac{e^{2ix}+1}{e^{2ix}-1}\] \[\cot(nx)=-i\frac{e^{2nix}+1}{e^{2nix}-1\]

Performing the substitution \(u=e^{2ix}\), we get \(\cot(x)=i\frac{u+1}{u-1}\) and \(\cot(nx)=i\frac{u^n+1}{u^n-1}\)

\(i\) in \(\mb F_i\)

Plugging in the values from the challenge, we have \(2=i(\frac{u+1}{u-1}\) and \(c=i\frac{u^n+1}{u^n-1}\) (where \(c=0x4e8f206f074f895bde336601f0c8a2e092f944d95b798b01449e9b155b4ce5a5ae93cc9c677ad942c32d374419d5512c\))

Now we need to somehow express \(i\) in \(\mb F_p\). Since \(i=\sqrt{-1}\), we simply need to find a number such that \(x^2=p-1 (mod p)\), which is trivial for \(p\neq1\pmod8\)(here \(p=5\pmod 8\)). Both solutions would work here.

solving for \(u\), \(u^n\) and \(n\)

\begin{align*} u&=(2+i)/(2-i)\\\
c&=i(u^n+1)/(u^n-1)\\\
u^n&=(c+i)/(c-i)\\\
\end{align*}

Now it’s just a discrete log problem, which takes some time to solve (15mins on my old and broken laptop)

Flag: AceBear{_I_h0p3__y0u_3nj0y3d_1t_}