Exponentiation by Squaring Algorithm

In mathematics and computer programming, exponentiating by squaring is a general method for fast calculation of large positive integer powers of a number, or more generally of an component of a semigroup, like a polynomial or a square matrix. For semigroups for which additive notation is normally used, like elliptic curves used in cryptanalysis, this method is also referred to as double-and-add.

Exponentiation by Squaring source code, pseudocode and analysis