Encryption works by having a set way to jumble up data so that it appears random. For instance, you could use a formula that you add each digit in a key to each digit in the data in a loop.
key = 1234
data = 9875204565651930
encrypt = 9 + 1, 8 + 2, 7 + 3, 5 + 4, 2 + 1, 0 + 2, 4 + 3, 5 + 4, 6 + 1, 5 + 2, 6 + 3, 5 + 4, 1 + 1, 9 + 2, 3 + 3, 0 + 4
= 0009327977992164
decrypt = 0 - 1, 0 - 2, 0 - 3, 9 - 4, 3 - 1, 2 - 2, 7 - 3, 9 - 4, 7 - 1, 7 - 2, 9 - 3, 9 - 4, 2 - 1, 1 - 2, 6 - 3, 4 - 4
= 9875204565651930
So even though the encrypted version does not look anything like the original data, it is obvious that there is a mathematical relationship between the encrypted data and the key that was used, and that relationship is the encryption method.
Now if you wanted to break this and knew the method, all you have to do is take the encrypted data and start trying numbers as the key. Eventually you will figure it out (since usually the original data will be meaningful to a human instead of just some random number I made by hitting keys.) Also, there may be ways to detect the key based on flaws in the encryption method. For instance, in the above scheme, if we weren’t paying attention and encrypted 000000000000000000 and sent it out, the encrypted version would be 123412341234123412…so yeah the person might guess what the key you are using is.
Now, let us assume that the people who make encryption methods are really, really smart and can think of mathematical ways to jumble up data that seem impossible to us.
In a simple encryption scheme like the one I used, you jumble the data by applying the key to it using some sort of math. To decrypt you simply reverse what you did to encrypt it. So if your process to encrypt is to add the key to each digit, you decrypt by subtracting the key from each.
If, however, we used multiplication and division instead of addition and subtraction, a magical thing happens. On computers, the amount of time it takes to multiply is much smaller than it takes to divide numbers. For instance, it may take 20 microseconds to get the result of multiplying any two numbers, but take 200 to get the result of any division operation. Addition and subtraction generally take the same amount of time.
This means that in any given moment one computer could send out hundreds of encrypted items, but another computer could only decrypt a tenth of those in the same amount of time. And it means that if you are trying to crack the encryption, it’s going to take your computer a lot longer to try every single possibility than if they had used addition and subtraction. And all the time you’re doing that, the person sending out encrypted messages will be changing his key periodically.
If the average length of data is, for instance, 500 bytes, and we need 20 microseconds to encrypt each byte and 200 to decrypt each. Plus we say that the minimum length of a key is 32 bits.
32 bits for a key means there are 4294967296 possible keys. It will take a person trying to figure out our key an average of 100000 microseconds (200 microseconds * 500 bytes) or, 1 second. On average, he will have to go through half of all the keys before he could find our key. So it will take him 2147483648 seconds from the time we start using a new key until it is broken. That is, about 4189 years.
Because it takes him longer to decrypt than it takes us time to encrypt, we automatically get 10 times the amount of time it will take before he can break the key, where otherwise we would have to use a key that is ten times longer.
But no encryption scheme is unbreakable. Just, like the above example, you can know how long it will take to break and make sure that the minimum key size is large enough that it is unfeasible to try and brute-force it (unless you have 4189 years to spare…)
However, since any encryption method has a relationship between the data and the key, it is theoretically possible to come up with ways to determine the key from the data running a smaller number of tests than a full brute-force attack will take. So a second part of coming up with an encryption scheme is figuring out all the shortcuts and determining that the key is long enough and the shortcut non-specific enough that it will still take 4189 years to run (given current computing speeds.) As computing speeds rise, though, you may have to increase the key-length. Or if more and better shortcuts are discovered, the encryption scheme itself might have to be scrapped.
Since encryption schemes are based around certain mathematical operations that work nicely for being able to munge and return data, any time a shortcut is determined, it will be applicable to the entire field. When they create new encryption schemes, they aren’t just coming up with random things to do with data. They know that certain operations can be performed in a certain order, and that given current and theoretical shortcuts, any given method will have a set probability for how long it will remain a viable method. It just relies on advances in finding shortcuts to be an evolutionary process rather than one where sudden revolutionary ideas can appear which flip everything on its head. So there it is a question of whether modern day mathematicians have advanced to a point where revolutionary ideas of that potential impact are all that probable.
Now, as to the basic question of “public” keys. Well getting back to the idea that cryptologists are really, really smart; public keys work through a method where you can have a function which spits out two numbers that are mathematically related if you use them as keys in a particular order in a particular encryption/decryption scheme. Specifically, if you try to do the reverse of what you did to encrypt the data, you will not get the original data back. It’s been munged in a way that makes the original key insufficient to return the data to a meaningful form. Using the private key, however, you can get the data back.
This isn’t any more secure, or any less breakable, it’s just really damn impressive that mankind was able to come up with such equations which are actually able to make it happen with mathematical certainty.