Created
April 10, 2011 11:19
-
-
Save pif/912262 to your computer and use it in GitHub Desktop.
MODPOW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://homepages.gold.ac.uk/rachel/Mods.doc | |
To compute x^n mod p | |
Initialise y=1; u=x mod p; | |
Repeat | |
If n is odd then y:=(y*u) mod p; | |
n:=n div 2; | |
u:=(u*u) mod p; | |
Until n==0; | |
Output y; | |
Here the u value is the successive squaring of x, and the y value is the multiplication together of the required squared values of x. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment