system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Public-key cryptography

How does the public-private key system work? Why does it work?
gpt
ELI5 example how public-key cryptography works:

Imagine persons A and B want to transfer secret message but they can only send packages to each other in mail which is unsecure. Anyone can steal a package and take what ever contents are inside or even swap them to something else.

In symmetric key cryptography they would use a locked box and they both would have a key for the lock. Problem is they can't exchange keys safely. If A buys locked box, how can he send key for it to B without possibility that someone steals the key and makes copies.

In public-key cryptography person A buys a lock (and keeps the key for it in some secure place) and sends the unlocked lock to person B. Person B then puts his message inside a box and locks it with A's lock. Then he can send it safely to A without anyone having access to the message.

Locks in the examples are cryptographic algorithms. Public-key algorithms are much more expensive to calculate so usually they are just used to do the key-exchange: both send a symmetric cryptography key to each other using public-key cryptography. From there on they just use the symmetric cryptography to encrypt their communication.