Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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

You're missing that "All exponentiations are done modulo a particular 1536-bit prime".

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.