You are asking a general question about the subject of encryption.
It's not a topic for a 1 line answer.
Google the following
"asymmetric cryptography"
"what is public private key pair encryption"
Find a copy of Simon Singh's book "The Code Book"
You will learn a lot more by starting there then what you are going to get here.
-------
Key pair encryption is based on an obscure relationship between larger prime numbers and their products.
first prime number 982450151
second prime number 982451581
product
982450151 * 982451581 = 965209704103638731
The private is key is made up of 982450151 and 982451581
The public key is 965209704103638731
lets says our message is "good luck"
To encrypt the message, send the message and public key of 965209704103638731 to MAGIC_FUNCTION_1 the result in something like "uhrn973hl"
To dcrypt, send "uhrn973hl" to MAGIC_FUNCTION_2 along with private key 982450151 and 982451581 and the message "good luck" is back
That's .001 percent of this monster from 10000 feet up. If you really want to understand this type of cryptography you won't get the answer here, you will have a lot of work to do. Once you understand the cryptography, then you can dive into the topic of digital signatures.
The easy answers you seek are not here.