Here is Eddie's take on the Diffie-Hellman Cryptosystem.
However, not using large enough key sizes can be a problem.
Given below is a generator , a prime and a public key such that for some private key .
Find
1 2 3 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
You could check for an explanation of the full algorithm in the Baby step Giant step wiki .
We want b such that g b ≡ B ( m o d p ) .
We choose a base β roughly the size of p .
For some b 0 , b 1 , we have b = b 0 β + b 1
We have, B ≡ g b ≡ g b 0 β + b 1 ≡ ( g β ) b 0 ⋅ g b 1 ( m o d p ) ⟹ B g − b 1 ≡ ( g β ) b 0 ( m o d p )
Now, we can reduce our work to roughly the square root of the size of p .
Here's the algorithm:
Build a hash table for all possible values of b 1 from 0 to β inclusive.
For each value of b 0 = 1 , 2 , ⋯ β , check if ( g β ) b 0 is in the hash table.
Terminate when you've found b 0 . Output b = b 0 β + b 1
Here is a Sage implementation: