Hello
I'm thinking in something like RSA public key.
The lock and the key store two encrypted key numbers.
The lock, using his internal encrypted number and a random number generates another one.
The key checks this number and if it's right (only a few are truly generated by the lock) generates another number with his own.
The lock checks the latter number and opens the lock.
This is very common in computer science, and has been mathematically proved to be really difficult to hack.
I speak about random numbers in order to repeating always the same, that could be eavesdropped.