Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Being new to software development and crypto in general, I thought I would write a simple p2p encrypted chat app using the otr protocol detailed here: https://otr.cypherpunks.ca/Protocol-v3-4.0.0.html

However, I am having an issue calculating g^x and g^y.

I have g =2 for a particular 1536-bit prime, as the protocol says. But when I try to calculate g**x, where x is a random 320 bit number (which I generate with random.getrandbits(320)), then python takes forever to calculate it.

Am I missing something important here? I realize I am trying to calculate an absolutely huge number, but I am absolutely confused because I think I am doing exactly what the protocol dictates. Can anyone point me in the right direction and give me some insight into what I'm doing wrong?

share|improve this question

1 Answer 1

You're missing that "All exponentiations are done modulo a particular 1536-bit prime".
See https://docs.python.org/3.1/library/functions.html#pow.

share|improve this answer
Thank you so much! –  user3213201 Jul 4 '14 at 3:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.