Calculating very large exponents in python

Mark Dickinson dickinsm at gmail.com
Mon Mar 8 20:21:14 CET 2010


[Replying to Geremy's reply because the OP's post didn't show up in my
newsreader.]
On Mar 7, 8:40 pm, geremy condra <debat... at gmail.com> wrote:
> On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad <miracles... at hotmail.com> wrote:
> > Dear All,
>
> > i am writing my crytographic scheme in python, i am just a new user to it.
> > I have written the complete code, the only point i am stuck it is that i am
> > using 256 exponentiation which is normal in crytography but python just
> > hangs on it.
>
> > g**x  [where both g and x are 256 bit numbers , in decimal they are around
> > 77]

No library can solve this problem.  If g and x are both 256-bit
numbers then the result of g**x will have on the order of 10**79 bits,
which matches estimates of the number of particles in the universe.  I
can only imagine that you actually want g**x % m for some m, in which
case three-argument pow is your friend, as Geremy pointed out.

--
Mark



More information about the Python-list mailing list