Home
Writeups Misc About
Real Eisenstein

Real Eisenstein

This challenge marks a really important point in my CryptoHack journey. I have conquered a lattice related challenge knowing what is going on. Lattices have been something I have zero idea about (and I would looove to stay away from), but thanks to the incredible help and explanation from Kel Zin, I can say I understand 0.01% of how lattices work now.

If we write the problem in mathematical terms, we have the following:

ct=i=1N2256aipi

where pi is the ith prime, and ai is the ASCII integer representation of the character.

A "lattice" like perspective on this, that is, there exists a linear combination of the values 2256pi very close to the given ciphertext ct. This is somewhat like a Shortest Vector Problem: there exists some ai such that

i=1Nai2256aipict

is very small. We are interested in the values of ai (which ideally should contain the ASCII integer value of the flag character), hence we can construct this basic matrix:

(1002256p10102256p20012256p3000ct)

The ideas of the 1 in the matrix is to keep track of the ai. The vectors in the lattice is the rows, and you can observe that some linear combinations of the rows, using the coefficients of a1,a2,...,an will lead to some shortest vector in the lattice space. The coefficients of the linear combinations should be relatively small, hence a "short" vector should exist.

This is time for the lattice magic (or more like Sage magic). Sagemath has implementations of two algorithms, LLL and BKZ which are both great in finding such short vectors. The content of the flag should be the first line (which is also the shortest vector in the new basis of the lattice field).

Sage Implementation: