Modular Exponentiation by Repeated Squaring
Compute a large power from the exponent’s binary expansion while keeping intermediate residues bounded.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Each squaring advances one binary place
For modulus \(m>1\) and nonnegative exponent \(e\), successively square \(a\bmod m\) to obtain residues for \(a^{2^i}\). Multiply the residues corresponding to set bits of \(e\), reducing after every operation. For \(5^{13}\bmod23\), the powers for \(1,2,4,8\) give \(5,2,4,16\). The exponent \(13=8+4+1\) selects \(16\cdot4\cdot5\equiv21\bmod23\). Only logarithmically many modular multiplications are needed.
Correctness and protective implementation are separate claims
Residue reduction respects multiplication, so keeping each intermediate small preserves the final class. An exponent-dependent execution pattern is appropriate for classroom arithmetic and must be avoided for secret exponents where the implementation model requires protection from observations. Cryptographic libraries implement the relevant arithmetic with side-channel contracts. Bit complexity accounts for each multiplication’s size. Diffie–Hellman uses exponentiation in a suitable group to agree on a shared value.[1]