whitenoise Posted December 11, 2015 Share Posted December 11, 2015 Hey, I'm trying to code some crypto stuff. I don't just want to simulate an algorithm but want to use numbers that are used in practice. During the calculations of a Diffie Hellman key exchange some large numbers have to be processed. There is a prime number with >2048 bits and a base with an exponent, where the exponent should have a size of around 160-256 bits. At the moment I'm having problems with finding the right data types for this big numbers. If I just try to calculate something like (p is not a prime here): p=123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789 b=2 x=987654321987654321987654321 A=b**x mod p Here for testing: #!/usr/bin/env python #-*- coding: utf-8 -*- p=123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789 b=2 x=987654321987654321987654321 A=b**x % p print A I run into a memory problem (MemoryError). Converting the int's to long does not help, using Decimal() does not help either. I was trying to use the datatypes of numpy (see here) but I get OverflowError: Python int too large to convert to C long Has anyone experience in handling such big numbers and doing arithmetics with them in python? I mean .. DH key exchange is something my browser does a hundreds time a day and it never told me it is out of memory so I guess there has to be a trick ;) Cheers! Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.