Content deleted Content added
Line 18:
Here is a C++ program for the iterative version of the discrete exponential function, which is more efficient than the recursive version.
#{
#//finds a^x mod n.▼
#Arbint e=1;
##{
## if(x%2==1){e=(e*a)%n; x=x -1;}▼
## a=(a*a)%n;▼
## x=x/2;▼
▲Arbint f(Arbint a, Arbint x, Arbint n){ //discrete exponentiation
## }▼
▲//finds a^x mod n.
#}
▲while(x!=0){
*Remarks
▲ if(x%2==1){e=(e*a)%n; x=x -1;}
*Arbint is a user defined data type of an arbitrary precision integer with the overloaded operations +, -, *, and % defined for the class.
▲ a=(a*a)%n;
▲ x=x/2;
▲ }
|