I understand the basic system of public vs. private keys and how if I want to send a person something, I need their public key and they decrypt with their private key, but what kind of logical mechanisms are at play so that a private key can decrypt what a public key encrypted? For example, say I wanted to write my own asynchronous key system. How would I go about generating these keys in pairs and how would I implement them?
I know there's not just one way to do it, but I am just trying to wrap my head around any way of doing it.