Fast Exponentiation
6
A simple tool used for fast Exponentiation. Very useful if you are creating your own cryptograpgic methods.
public class FastExpon
{
public long y = 1;
public long fex(long x, long e, long m)
{
while (e != 0)
{
if (e%2==0)
{
x=x*x%m;
e=e/2;
}
else
{
y=x*y%m;
e=e-1;
}
}
return y;
}
public long getAns()
{
return y;
}
public static void main(String[] args)
{
FastExpon f = new FastExpon();
System.out.println(f.fex(6916502,2773637,9326363));
}
}
Comments
Tue. Sep. 19th, 2006 8:27 AM
alambkin
alambkin





