I’ve been trying to get my head around this and I’ve watched a few videos but they don’t seem to specifically answer my question.
According to what I’ve found online, messages encrypted with a public key can only be decrypted with a private key. But in practice, how is that possible?
Surely a public key contains a set of instructions, and anyone could just run those instructions in reverse to decrypt a message? If everything you need to encrypt a message is stored within a public key, then how is it a one-way process?
It’s likely that I’m misunderstanding a core element of this!
Look at the Diffie Helman scheme, with the example used in the Wikipedia page.
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).