Skip to content

Instantly share code, notes, and snippets.

@dimmaq
Created December 26, 2012 08:34
Show Gist options
  • Select an option

  • Save dimmaq/4378919 to your computer and use it in GitHub Desktop.

Select an option

Save dimmaq/4378919 to your computer and use it in GitHub Desktop.
Diffie-Hellman DH test on Python
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> g=2
>>> p=3249307499
>>> import random
>>> a=random.randint(10000,99999)
>>> b=random.randint(10000,99999)
>>> A = g**a % p
>>> B = g**b % p
>>> s1 = A**b % p
>>> s2 = B**a % p
>>> s1==s2
True
>>> A
1197208244
>>> B
1352346351
>>> s1
2762163432
>>> s2
2762163432
>>> a
45702
>>> b
94084
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment