Challenges
Tonelli-Shanks: modular square root
Cryptography
Medium
Modular square root
Solves: 6
Tonelli-Shanks: modular square root
Author: CyberSamSU
Points
45
In the previous challenge, because p ≡ 3 (mod 4), we found the square root with a single formula. Here, however, p ≡ 1 (mod 8) — that formula does not work, and a general algorithm is needed.
The Tonelli-Shanks algorithm is for exactly this task: it solves the equation x² ≡ a (mod p) for any odd prime p. The algorithm writes p-1 = 2^s · q (where q is odd), finds a quadratic non-residue, and step-by-step applies a "correction" multiplier.
Find the square roots of the following a modulo mod p. Submit the smaller of the two roots as the answer.
p = 18125264933088838729
a = 2255170422501462431
Answer: only a number — in decimal format, without spaces and additional characters (for example 1234).
To submit a flag, log in.