Skip to main content
Challenges Baby-step, giant-step
Cryptography Hard Discrete logarithm Solves: 8

Baby-step, giant-step

Author: CyberSamSU
Points
80

Now p is 13 digits long. A simple brute force search requires about 10¹² steps — this is several days in Python. But there is a universal algorithm that solves the discrete logarithm much faster.

Baby-step giant-step (BSGS) — reduces time at the expense of memory. The idea is simple: let m = ⌈√n⌉ and write the unknown x in the form x = i·m + j, where 0 ≤ i, j < m. Then:

g^(i*m + j) = h   (mod p)
g^j = h * (g^(-m))^i   (mod p)

The algorithm consists of two stages. Baby steps: all values of g^j are written to a dictionary (dict) — m entries. Giant steps: h · (g^(-m))^i is calculated sequentially, and each time it is searched for in the dictionary. When a match is found, x = i·m + j. In total ~2√n steps, which means a few million in this challenge — a few seconds.

Intercepted session:

p = 1379880546293
g = 2

A = 666436569524
B = 989835935547

Find the shared secret s (you must first recover a or b).

Flag: BAYROQ{DH_bsgs_sir_<s>}. The dictionary will consist of ~10⁶ entries — this is normal.

Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −8 pts Log in
Hint 2 −16 pts Log in
Hint 3 −24 pts Log in
To submit a flag, log in.

First solvers

1. Абдул 08.09.2026
2. Stiv_084100 11.09.2026
3. W.o.X 17.09.2026
4. Лазиз 04.10.2026
5. testrejim 09.10.2026
6. Mirjaxon Qaxxarov 27.10.2026
7. Odam 05.11.2026
8. arcanum 11.11.2026