Consider a dormitory building with $N$ rooms $R_1$ to $R_N$. The $i^\text{th}\text{ resident }(i \in [N])$ has a key $K_i$ to his own room $R_{i}$. Let $L_{i}$ be the lock on room $R_{i}$. Naturally, $K_i$ and $L_i$ are one-to-one mapped; key $K_i$ cannot open lock $L_j$ unless $i = j$.
The administrator has a master key $K'$ capable of opening all locks $L_i, i \in [N]$.
Also, the dormitory has a common main door, with lock $L'$ that can be opened by any key $K_i, i \in [N]$, and also the administrator's master key $K'$. (We shall call this lock 'slave lock' as against 'master key'). However, this lock cannot be opened by any other key(s).
I'm looking for a mathematical representation, and a sample one-to-one mapping function (such that the function also satisfies the master key and slave lock entities).
EDIT: I'm looking for an algorithm or a function $y = f(x)$ of some sort that will help produce combinations for the locks and keys, and also define what the master key and slave lock would be in the domain considered.
Here's a schematic diagram: