[Tutor] Is there a Big Integer Class in Python?

Alan Gauld alan.gauld at btinternet.com
Tue Dec 22 08:29:25 EST 2015


On 22/12/15 10:05, Satya Luzy wrote:
> I'm currently making a cryptanalysis program that involves up to 150
> integer digits.
> The number will be used for multiplication and exponentiation purpose.
> So, do I need to use something like a big integer class? or does that even
> exist?

Python integers are effectively big integers, no need of a special
class. Just use normal integers.

If in doubt try this (using Python v2):

>>> print 2 ** 500
327339060789614187001318969682759915221664204604306
478948329136809613379640467455488327009232590415715
0886684127560071009217256545885393053328527589376L

Notice the L at the end? That tells you python is using a
long integer. You only see that in Python v2. If you are
using v3 there is no L and no distinction between long
and regular integers.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list