Solution (source code)

= Solution

For a prime $p>2$, a diagonal <matrix> with two distinct nonzero <eigenvalues> exists. The same common-eigenspace argument makes the <normalizer of a diagonal subgroup of GL2> precisely the monomial <matrices>. There are $(p-1)^2$ choices of nonzero entries for each of two permutation patterns, giving
$$
\boxed{|N|=2(p-1)^2\quad(p>2).}
$$
At $p=2$, however, the invertible diagonal <subgroup> is trivial. Every invertible <matrix> normalizes it, so
$$
\boxed{N=GL_2(\mathbb F_2),\qquad |N|=(2^2-1)(2^2-2)=6.}
$$
The first factor chooses a nonzero first column and the second chooses a column outside its one-dimensional span. The exceptional answer is necessary because the printed question permits every prime.