It depends on the exact algorithm used for encryption, but a decryption does not have to be identical to the encryption (though that is a poor way to say it)
But what I think you are referring to are the common public/private key exchanges that take place between individuals, CA, and servers, etc.
Basically you make an encryption with more than one answer, but only give one answer to a second party. As long as the originating party keeps their half 'private' you always know messages, or what have you, come from them.
Basically it uses 2 prime numbers in order to generate big numbers that are difficult to factorize. It uses the mathematical "features" that prime numbers have in order to obtain the 2 keys. The exact functionality is a bit difficult to explain, but you can see here at this wikipedia entry for RSA (an asymmetrical encryption algorithm):