[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Calculating very large exponents in python

geremy condra

3/7/2010 8:41:00 PM

On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad <miraclesoul@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]
>
> after reading several forums, i just come to know it can be done using
> numpy, i have installed python(x,y) has has both numpy and scipy installed
> but i am not able to make it happen.
>
> any idea which library, module, or piece of code can solve this mystery :S
>
> sorry for bad english

A couple of things:

1) if you're working with modular exponentiation, remember that pow() takes
three arguments, ie:

a = 222222222222222222222222222
b = 5555555555555555555555555555
pow(a, b, 1200)

will calculate the correct answer (768) very quickly, while

a**b % 1200

has not terminated in the time it took me to compose this
email.

2) sage has a lot of excellent tools for crypto/cryptanalysis that you
may want to take a look at.

3) not saying you don't know what you're doing, but be careful when
rolling your own cryptosystems- even very good cryptographers make
implementation mistakes!

Geremy Condra
1 Answer

Mark Dickinson

3/8/2010 7:21:00 PM

0

[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...@gmail.com> wrote:
> On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad <miracles...@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