Two-dimensional key space search algorithm.