Endomorphisms of the ring $(\mathbb{Z}/p\mathbb{Z})^n$ Describe the set of Endormorphisms of the ring $ K = (\mathbb{Z}/p\mathbb{Z})^n$ where $p$ is prime.

I think my main difficulty is viewing $K$ as ring versus viewing it as a $\mathbb{Z}/p\mathbb{Z}$-vector space. Where viewing it as a vector space wouldn't be right because we don't multiply vectors. So $n \times n$ matrices wouldn't be right, right?
 A: The set of ring-endomorphisms of a commutative ring is just a monoid in general.
Let $X = \{1,\ldots, n\}$ and $k = \mathbb{F}_p$. Then there is an isomorphism of rings $\psi : K \to Fun(X,k)$ given by $\psi(v)(i) = v_i$ for all $i \in X$. 
Now $Y \mapsto Fun(Y,k)$ is a contravariant functor from sets to commutative rings. This means that there is a monoid anti-homomorphism 
$$\varphi : End(X) \to End(Fun(X,k))$$ 
given by
$$\varphi(\alpha)(f) = f \circ \alpha.$$ 
We will show that $\varphi$ is a bijection. It will follow that $End(K)$ is anti-isomorphic to the monoid of all functions $X\to X$ under composition.
Note that $Fun(X,k)$ is a $k$-vector space, with basis given by the delta functions $\{\delta_x : x\in X\}$ which are defined by $\delta_x(y) = 1$ if $y = x$ and $\delta_x(y) = 0$ otherwise.
If $\alpha, \beta : X\to X$ are distinct functions then $\alpha(x) \neq \beta(x)$ for some $x \in X$, but then $\delta_{\alpha(x)}\circ \alpha \neq \delta_{\alpha(x)} \circ \beta$ because the first takes value $1$ at $x$ and the second takes value $0$ at $x$. So $\varphi(\alpha)\neq \varphi(\beta)$ and $\varphi$ is injective. 
If $\theta : Fun(X,k) \to Fun(X,k)$ is a ring homomorphism then $\theta(\delta_x)$ is an idempotent for all $x\in K$ so $\theta(\delta_x) = \delta_{S(x)}$ for some subset $S(x)$ of $X$. Since $\{\delta_x : x \in X\}$ forms a complete set of orthogonal idempotents in $Fun(X,k)$, their image under $\theta$, namely $\{\delta_{S(x)} : x\in K\}$, must also form a complete set of orthogonal idempotents. This means that $S(x) \cap S(y) = \emptyset$ if $x\neq y$ and $\cup_{x\in X}S(x) = X$. In other words, $\{S(x) : x \in X\}$ is a partition of $X$ into at most $n$ parts (some $S(x)$ could well be empty). Let $g : X \to X$ be defined by $g(y) = x$ if $y \in S(x)$. This is well-defined since $\{S(x) : x \in X\}$ is a partition, and then $S(x) = g^{-1}(\{x\})$ for all $x \in X$ by construction. Now, using the Kronecker delta we compute 
$$[\varphi(g)(\delta_x)](y) = [\delta_x \circ g](y) = \delta_{x,g(y)} = \delta_{y \in g^{-1}(\{x\})} = \delta_{g^{-1}(x)}(y) = \delta_{S(x)}(y) = \theta(\delta_x)(y)$$
for all $x,y\in X$. Now, the subring of constant functions in $Fun(X,k)$ is the prime subfield of $Fun(X,k)$ because $k = \mathbb{F}_p$. So the restriction of $\theta$ to $k$ is the identity map. Hence $\theta$ is a $k$-linear, and therefore is completely determined by its values on the basis $\{\delta_x : x\in X\}$. Hence $\theta = \varphi(g)$ and $\varphi$ is surjective.
This can be viewed as a consequence of the equivalence of categories between the category of commutative rings and the opposite of the category of affine schemes.
