Fast Exponentiation





6
Date Submitted Wed. Sep. 13th, 2006 9:47 AM
Revision 1 of 1
Helper alambkin
Tags Exponentiation | Fast | Java
Comments 1 comments
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));
        }
}
 

Alan Lambkin

Comments

Comments Old version
Tue. Sep. 19th, 2006 8:27 AM    Helper alambkin

Voting