{"action":"created","comment":{"url":"https://api.github.com/repos/sympy/sympy/pulls/comments/47238784","id":47238784,"diff_hunk":"@@ -1589,3 +1589,126 @@ def decipher_elgamal(ct, prk):\n     \"\"\"\n     u = igcdex(ct[0] ** prk[2], prk[0])[0]\n     return u * ct[1] % prk[0]\n+\n+\n+#################### Diffie-Hellman Key Exchange  #############################\n+\n+def dh_private_key(digit = 10):\n+    \"\"\"\n+    Return two number tuple as private key.\n+\n+    Diffie-Hellman key exchange is based on the mathematical problem\n+    called the Discrete Logarithm Problem (see ElGamal).\n+\n+    Diffie-Hellman key exchange is divided into the following steps:\n+\n+    *   Alice and Bob agree on a base that consist of a prime p and a\n+        primitive root of p called g\n+    *   Alice choses a number a and Bob choses a number b where a\n+        and b are random numbers with 1 < a, b < p. These are their\n+        private keys.\n+    *   Alice then publicly sends Bob `g^{a} \\pmod p` while Bob sends\n+        Alice `g^{b} \\pmod p`\n+    *   They both raise the received value to their secretly chose number\n+        (a or b) and now have both as their shared key `g^{ab} \\pmod p`\n+\n+    Parameters\n+    ==========\n+\n+    digit: Key length in binary\n+\n+    Returns\n+    =======\n+\n+    (p, g, a) : p = prime number, g = primitive root of p,\n+                a = random number in between 2 and p - 1\n+\n+    Examples\n+    ========\n+\n+    >>> from sympy.crypto.crypto import dh_private_key\n+    >>> from sympy.ntheory import isprime, is_primitive_root\n+    >>> dh_private_key()\n+    (1031, 14, 66)\n+    >>> isprime(1031)\n+    True\n+    >>> is_primitive_root(14, 1031)\n+    True\n+    >>> dh_private_key(5)\n+    (37, 2, 31)\n+    >>> isprime(37)\n+    True\n+    >>> is_primitive_root(2, 37)\n+    True\n+\n+    \"\"\"\n+    p = nextprime(2 ** digit)\n+    g = primitive_root(p)\n+    a = randrange(2, p)\n+    return p, g, a\n+\n+def dh_public_key(prk):\n+    \"\"\"\n+    Return two number tuple as public key.\n+\n+    This is the tuple that Alice sends to Bob.\n+\n+    Parameters\n+    ==========\n+\n+    prk: Tuple (p, g, a) generated by ``dh_private_key``\n+\n+    Returns\n+    =======\n+\n+    (p, g, g^a mod p) : p, g and a as in Parameters\n+\n+    Examples\n+    ========\n+\n+    >>> from sympy.crypto.crypto import dh_private_key, dh_public_key\n+    >>> prk = dh_private_key(); prk\n+    (1031, 14, 66)\n+    >>> dh_public_key(prk)\n+    (1031, 14, 200)\n+\n+    \"\"\"\n+    p, g, a = prk\n+    return p, g, pow(g, a, p)\n+\n+def dh_shared_key(puk, b):\n+    \"\"\"\n+    Return int as shared key.\n+\n+    This is what Bob and Alice can both calculate using the public\n+    keys their received from each other and their private keys.","path":"sympy/crypto/crypto.py","position":96,"original_position":96,"commit_id":"8b460a88696b1dd3e2686d630f62d5170cd4322f","original_commit_id":"8b460a88696b1dd3e2686d630f62d5170cd4322f","user":{"login":"smichr","id":90703,"avatar_url":"https://avatars.githubusercontent.com/u/90703?v=3","gravatar_id":"","url":"https://api.github.com/users/smichr","html_url":"https://github.com/smichr","followers_url":"https://api.github.com/users/smichr/followers","following_url":"https://api.github.com/users/smichr/following{/other_user}","gists_url":"https://api.github.com/users/smichr/gists{/gist_id}","starred_url":"https://api.github.com/users/smichr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smichr/subscriptions","organizations_url":"https://api.github.com/users/smichr/orgs","repos_url":"https://api.github.com/users/smichr/repos","events_url":"https://api.github.com/users/smichr/events{/privacy}","received_events_url":"https://api.github.com/users/smichr/received_events","type":"User","site_admin":false},"body":"their received -> they received","created_at":"2015-12-10T15:24:28Z","updated_at":"2015-12-10T15:24:28Z","html_url":"https://github.com/sympy/sympy/pull/10223#discussion_r47238784","pull_request_url":"https://api.github.com/repos/sympy/sympy/pulls/10223","_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments/47238784"},"html":{"href":"https://github.com/sympy/sympy/pull/10223#discussion_r47238784"},"pull_request":{"href":"https://api.github.com/repos/sympy/sympy/pulls/10223"}}},"pull_request":{"url":"https://api.github.com/repos/sympy/sympy/pulls/10223","id":53246857,"html_url":"https://github.com/sympy/sympy/pull/10223","diff_url":"https://github.com/sympy/sympy/pull/10223.diff","patch_url":"https://github.com/sympy/sympy/pull/10223.patch","issue_url":"https://api.github.com/repos/sympy/sympy/issues/10223","number":10223,"state":"open","locked":false,"title":"Crypto: Implementation of Diffie-Hellman key exchange","user":{"login":"ec-m","id":10234559,"avatar_url":"https://avatars.githubusercontent.com/u/10234559?v=3","gravatar_id":"","url":"https://api.github.com/users/ec-m","html_url":"https://github.com/ec-m","followers_url":"https://api.github.com/users/ec-m/followers","following_url":"https://api.github.com/users/ec-m/following{/other_user}","gists_url":"https://api.github.com/users/ec-m/gists{/gist_id}","starred_url":"https://api.github.com/users/ec-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ec-m/subscriptions","organizations_url":"https://api.github.com/users/ec-m/orgs","repos_url":"https://api.github.com/users/ec-m/repos","events_url":"https://api.github.com/users/ec-m/events{/privacy}","received_events_url":"https://api.github.com/users/ec-m/received_events","type":"User","site_admin":false},"body":"The checks give me as a failed example:\r\n\r\n > prk = dh_private_key(); prk\r\n> Expected:\r\n> (1031, 14, 66)\r\n> Got:\r\n > (1031, 14, 176)\r\n\r\nwhich is probably due to the fact that the last element is a random number in between 2 and 1030. How can I avoid the checks failing if this is what is suppose to happen?","created_at":"2015-12-10T11:33:53Z","updated_at":"2015-12-10T15:24:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ce5a131cc41f19bbc8a826fd88b390e5e76733eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sympy/sympy/pulls/10223/commits","review_comments_url":"https://api.github.com/repos/sympy/sympy/pulls/10223/comments","review_comment_url":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/10223/comments","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/8b460a88696b1dd3e2686d630f62d5170cd4322f","head":{"label":"ec-m:crypto_diffiehellman","ref":"crypto_diffiehellman","sha":"8b460a88696b1dd3e2686d630f62d5170cd4322f","user":{"login":"ec-m","id":10234559,"avatar_url":"https://avatars.githubusercontent.com/u/10234559?v=3","gravatar_id":"","url":"https://api.github.com/users/ec-m","html_url":"https://github.com/ec-m","followers_url":"https://api.github.com/users/ec-m/followers","following_url":"https://api.github.com/users/ec-m/following{/other_user}","gists_url":"https://api.github.com/users/ec-m/gists{/gist_id}","starred_url":"https://api.github.com/users/ec-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ec-m/subscriptions","organizations_url":"https://api.github.com/users/ec-m/orgs","repos_url":"https://api.github.com/users/ec-m/repos","events_url":"https://api.github.com/users/ec-m/events{/privacy}","received_events_url":"https://api.github.com/users/ec-m/received_events","type":"User","site_admin":false},"repo":{"id":47689041,"name":"sympy","full_name":"ec-m/sympy","owner":{"login":"ec-m","id":10234559,"avatar_url":"https://avatars.githubusercontent.com/u/10234559?v=3","gravatar_id":"","url":"https://api.github.com/users/ec-m","html_url":"https://github.com/ec-m","followers_url":"https://api.github.com/users/ec-m/followers","following_url":"https://api.github.com/users/ec-m/following{/other_user}","gists_url":"https://api.github.com/users/ec-m/gists{/gist_id}","starred_url":"https://api.github.com/users/ec-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ec-m/subscriptions","organizations_url":"https://api.github.com/users/ec-m/orgs","repos_url":"https://api.github.com/users/ec-m/repos","events_url":"https://api.github.com/users/ec-m/events{/privacy}","received_events_url":"https://api.github.com/users/ec-m/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ec-m/sympy","description":"A computer algebra system written in pure Python","fork":true,"url":"https://api.github.com/repos/ec-m/sympy","forks_url":"https://api.github.com/repos/ec-m/sympy/forks","keys_url":"https://api.github.com/repos/ec-m/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ec-m/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ec-m/sympy/teams","hooks_url":"https://api.github.com/repos/ec-m/sympy/hooks","issue_events_url":"https://api.github.com/repos/ec-m/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/ec-m/sympy/events","assignees_url":"https://api.github.com/repos/ec-m/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/ec-m/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/ec-m/sympy/tags","blobs_url":"https://api.github.com/repos/ec-m/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ec-m/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ec-m/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ec-m/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ec-m/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/ec-m/sympy/languages","stargazers_url":"https://api.github.com/repos/ec-m/sympy/stargazers","contributors_url":"https://api.github.com/repos/ec-m/sympy/contributors","subscribers_url":"https://api.github.com/repos/ec-m/sympy/subscribers","subscription_url":"https://api.github.com/repos/ec-m/sympy/subscription","commits_url":"https://api.github.com/repos/ec-m/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ec-m/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ec-m/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ec-m/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ec-m/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/ec-m/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ec-m/sympy/merges","archive_url":"https://api.github.com/repos/ec-m/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ec-m/sympy/downloads","issues_url":"https://api.github.com/repos/ec-m/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/ec-m/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/ec-m/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/ec-m/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ec-m/sympy/labels{/name}","releases_url":"https://api.github.com/repos/ec-m/sympy/releases{/id}","created_at":"2015-12-09T12:08:59Z","updated_at":"2015-12-09T12:09:04Z","pushed_at":"2015-12-10T10:59:09Z","git_url":"git://github.com/ec-m/sympy.git","ssh_url":"git@github.com:ec-m/sympy.git","clone_url":"https://github.com/ec-m/sympy.git","svn_url":"https://github.com/ec-m/sympy","homepage":"http://sympy.org/","size":73029,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sympy:master","ref":"master","sha":"e30a24be99982efa93b68bb52ccfa4f279c7d1da","user":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"repo":{"id":640534,"name":"sympy","full_name":"sympy/sympy","owner":{"login":"sympy","id":260832,"avatar_url":"https://avatars.githubusercontent.com/u/260832?v=3","gravatar_id":"","url":"https://api.github.com/users/sympy","html_url":"https://github.com/sympy","followers_url":"https://api.github.com/users/sympy/followers","following_url":"https://api.github.com/users/sympy/following{/other_user}","gists_url":"https://api.github.com/users/sympy/gists{/gist_id}","starred_url":"https://api.github.com/users/sympy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sympy/subscriptions","organizations_url":"https://api.github.com/users/sympy/orgs","repos_url":"https://api.github.com/users/sympy/repos","events_url":"https://api.github.com/users/sympy/events{/privacy}","received_events_url":"https://api.github.com/users/sympy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sympy/sympy","description":"A computer algebra system written in pure Python","fork":false,"url":"https://api.github.com/repos/sympy/sympy","forks_url":"https://api.github.com/repos/sympy/sympy/forks","keys_url":"https://api.github.com/repos/sympy/sympy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sympy/sympy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sympy/sympy/teams","hooks_url":"https://api.github.com/repos/sympy/sympy/hooks","issue_events_url":"https://api.github.com/repos/sympy/sympy/issues/events{/number}","events_url":"https://api.github.com/repos/sympy/sympy/events","assignees_url":"https://api.github.com/repos/sympy/sympy/assignees{/user}","branches_url":"https://api.github.com/repos/sympy/sympy/branches{/branch}","tags_url":"https://api.github.com/repos/sympy/sympy/tags","blobs_url":"https://api.github.com/repos/sympy/sympy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sympy/sympy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sympy/sympy/git/refs{/sha}","trees_url":"https://api.github.com/repos/sympy/sympy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sympy/sympy/statuses/{sha}","languages_url":"https://api.github.com/repos/sympy/sympy/languages","stargazers_url":"https://api.github.com/repos/sympy/sympy/stargazers","contributors_url":"https://api.github.com/repos/sympy/sympy/contributors","subscribers_url":"https://api.github.com/repos/sympy/sympy/subscribers","subscription_url":"https://api.github.com/repos/sympy/sympy/subscription","commits_url":"https://api.github.com/repos/sympy/sympy/commits{/sha}","git_commits_url":"https://api.github.com/repos/sympy/sympy/git/commits{/sha}","comments_url":"https://api.github.com/repos/sympy/sympy/comments{/number}","issue_comment_url":"https://api.github.com/repos/sympy/sympy/issues/comments{/number}","contents_url":"https://api.github.com/repos/sympy/sympy/contents/{+path}","compare_url":"https://api.github.com/repos/sympy/sympy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sympy/sympy/merges","archive_url":"https://api.github.com/repos/sympy/sympy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sympy/sympy/downloads","issues_url":"https://api.github.com/repos/sympy/sympy/issues{/number}","pulls_url":"https://api.github.com/repos/sympy/sympy/pulls{/number}","milestones_url":"https://api.github.com/repos/sympy/sympy/milestones{/number}","notifications_url":"https://api.github.com/repos/sympy/sympy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sympy/sympy/labels{/name}","releases_url":"https://api.github.com/repos/sympy/sympy/releases{/id}","created_at":"2010-04-30T20:37:14Z","updated_at":"2015-12-10T13:39:02Z","pushed_at":"2015-12-10T14:08:07Z","git_url":"git://github.com/sympy/sympy.git","ssh_url":"git@github.com:sympy/sympy.git","clone_url":"https://github.com/sympy/sympy.git","svn_url":"https://github.com/sympy/sympy","homepage":"http://sympy.org/","size":102100,"stargazers_count":2503,"watchers_count":2503,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1220,"mirror_url":null,"open_issues_count":2082,"forks":1220,"open_issues":2082,"watchers":2503,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sympy/sympy/pulls/10223"},"html":{"href":"https://github.com/sympy/sympy/pull/10223"},"issue":{"href":"https://api.github.com/repos/sympy/sympy/issues/10223"},"comments":{"href":"https://api.github.com/repos/sympy/sympy/issues/10223/comments"},"review_comments":{"href":"https://api.github.com/repos/sympy/sympy/pulls/10223/comments"},"review_comment":{"href":"https://api.github.com/repos/sympy/sympy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sympy/sympy/pulls/10223/commits"},"statuses":{"href":"https://api.github.com/repos/sympy/sympy/statuses/8b460a88696b1dd3e2686d630f62d5170cd4322f"}}}}