Efficient (HUGE) prime modulus

Hrvoje Niksic hniksic at xemacs.org
Mon Nov 19 12:14:40 EST 2007


blaine <frikker at gmail.com> writes:

> Python Code:
>     G =
> long(2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603)
>     P =
> long(7897383601534681724700886135766287333879367007236994792380151951185032550914983506148400098806010880449684316518296830583436041101740143835597057941064647)
>
>     a = self.rand_long(1) # 512 bit long integer
>
>     A = (G ** a) % P # G^a mod P
[...]
> I used math.pow and built-in pow. [...]  Is there a python
> implementation of java's Modpow?

Have you read the documentation of the built-in pow?  It has exactly
the functionality you need:

>>> A = pow(G, a, P)
... executes in several milliseconda ...



More information about the Python-list mailing list