Fermat factorization
The programmer wanted to speed up key generation: they found one prime number, and then chose the next one simply slightly larger than it. The modulus is 2048-bit, seemingly robust. But in reality, it is broken in one second.
Fermat's method is based on this: if n = p·q, assuming a = (p+q)/2 and b = (q−p)/2, it will be n = a² − b². When p and q are close, b is very small, and a is almost equal to √n.
Algorithm: starting from a = ⌈√n⌉, at each step we check whether a² − n is a perfect square. When a perfect square is found, b = √(a²−n), and p = a − b, q = a + b.
The key and ciphertext are in the kalit.txt file. Decrypt the message — the decrypted bytes directly give the flag.
Use math.isqrt — float root does not work at all for a 617-digit number.