Apex › Cryptography
Square roots mod a prime (Tonelli–Shanks)
Solve x² ≡ n (mod p). Only half the residues are perfect squares (quadratic residues, two roots each); Euler’s criterion n^((p−1)/2) ≡ 1 says which. If p ≡ 3 (mod 4) the root is one exponentiation n^((p+1)/4); otherwise Tonelli–Shanks factors p−1 = Q·2^S, grabs a non-residue, and iterates to the root in O(log²p). The headline use: elliptic-curve point decompression — a compressed key stores only x and a sign bit, and recovering y = √(x³+ax+b) mod p needs a modular square root. Verified in node: x²≡n for every residue and null for every non-residue across 16 primes (916 roots), both branches, both roots x and p−x. Click a residue to test it and find its roots.
More in Cryptography
- Cryptography
- Classical ciphers
- One-time pad
- AES internals
- ECB penguin / modes
- Feistel / DES
- CTR & AEAD
- ChaCha20
- Poly1305 MAC
- Timing attacks
- SHA-256 internals
- Broken hashes
- Length-extension attack
- HMAC
- Padding oracle attack
- Montgomery multiplication
- How public-key crypto works
- RSA
- Is this number prime? (Miller–Rabin)
- Finding a factor by accident (Pollard’s rho)
- One number, many remainders (Chinese Remainder Theorem)
- Dividing mod m (extended Euclid & the modular inverse)
- Elliptic curves
- Exponentiation that doesn’t leak (Montgomery ladder)
- ECDSA & nonce reuse
- EdDSA (Ed25519)
- Pedersen commitment
- Blind signatures
- Verifiable random function
- Oblivious transfer
- Compute on secrets (Yao garbled circuits)
- Hiding what you access (Path ORAM)
- Fetching a record privately (PIR)
- Homomorphic (Paillier)
- ElGamal encryption
- Zero-knowledge (Schnorr)
- One signature for a thousand signers (BLS aggregation)
- Proving a huge sum cheaply (sumcheck)
- A clock you can’t rush (verifiable delay function)
- Diffie–Hellman
- Cracking a discrete log (baby-step giant-step)
- DH man-in-the-middle
- TLS downgrade
- How HTTPS secures a connection
- Password hashing
- Post-quantum (LWE)
- How LLL reduces a lattice (& breaks crypto)
- NTT (Kyber engine)
- Quantum key (BB84)
- Secret sharing
- Envelope encryption (KMS)
- Verifiable secret sharing
- Threshold signatures
- Proof of Work
- Double Ratchet
- X3DH key agreement
- MLS / TreeKEM (group messaging)
- Merkle tree
- A whole set in one number (RSA accumulator)
- Lamport signatures
- Hash chain