Skip to main content
Challenges Fermat factorization
Cryptography Medium Factorization Solves: 7

Fermat factorization

Author: CyberSamSU
Points
60

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.

Attached files
kalit.txt Log in to download
SHA-256 checksums
kalit.txt: 1c0d45a014b636d15faf016302f3aca5c5412ddcc75b8480d93e3a9a5ff242af
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −6 pts Log in
Hint 2 −12 pts Log in
Hint 3 −18 pts Log in
To submit a flag, log in.

First solvers

1. W.o.X 17.09.2026
2. Лазиз 04.10.2026
3. testrejim 09.10.2026
4. Mirjaxon Qaxxarov 27.10.2026
5. Odam 05.11.2026
6. arcanum 11.11.2026
7. Doston Allayarov 28.11.2026