Comment on With public key cryptography, why can't someone decrypt a message using the public key?
GamingChairModel@lemmy.world 7 months ago
Look at the Diffie Helman scheme, with the example used in the Wikipedia page.
- Alice and Bob agree in public, for everyone to see, that they’re gonna start with p=23 and g=5.
- Alice has a secret key 4, and doesn’t tell anyone (not even Bob). She plugs her secret into the formula g^secret mod p, or 5^4 mod 23. 5^4 is 625, and dividing 625 into 23 gives a remainder of 4. So she tells Bob in public that she derived the number 4 from her secret.
- Bob has a secret key of 3, does the same thing, and calculates 5^3 mod 23, which results in the number of 10, tells Alice.
The magic of this scheme is that taking each side’s result and applying the same secret gets to the same final result. 10^4 mod 23 turns out to be the exact same number as 4^3 mod 23. So both sides get to the secret shared key 18, without disclosing that their secret numbers were 4 and 3, respectively.
But if you try to drive the secret key from the information publicly exchanged, you’ll basically have to try each number until you get to the right one. It’s inefficient, and basically impossible to do once you’re using very large integers (300+ digits long).