Cryptographic problem - locks
This seems to be a variation of Shamir's 3-pass protocol.

I guess that the card trick requires commutative encryption to work, meaning that encrypting with a key K_1 and then with another key K_2 will produce the same result as encrypting with K_2 and then K_1.

Most public-key encryption algorithms do NOT have this feature (at least, RSA and Elgamal do not).