Modern cryptography is founded on the idea that the key that you use to encrypt your data can be made public while the key that is used to to decrypt your data can be kept private.
What you need for a public key cryptographic system to work is a set of algorithms that is easy to process in one direction, but difficult to undo.
Algorithms that have this characteristic — easy in one direction, hard the other — are known as Trap door Functions.
In RSA, this maximum value (call it max) is obtained by multiplying two random prime numbers.
To encrypt a number you multiply it by itself pub times, making sure to wrap around when you hit the maximum.
To decrypt a message, you multiply it by itself priv times
In an ideal Trapdoor Function, the easy way and the hard way get harder at the same rate with respect to the size of the numbers in question.