We consider the combinatorial complexity of the algorithmic design of mecha
nical master key locking systems. Such locking systems use pin tumblers and
profile elements (wards) to realize the functional dependencies given by a
key/cylinder matrix. We prove that even very restricted versions of the ma
sterkeying problem are NP-complete. We show that the general masterkeying p
roblem can be defined by an integer linear program whose number of variable
s and restrictions is polynomial in the size of the key/cylinder matrix and
the size of the locking system. Heuristic solutions are also discussed.