Let $q\in \mathbb{N}$. For any Dirichlet character $\chi$ modulo $q$, er have $\phi(q)\sum_{a=1}^{q}\chi(a)=\mathbf{1}_{\chi=\chi_0}$.
The case $\chi=\chi_0$ is easy to prove. Suppose $\chi\neq \chi_0$. Then there exists $k\in \mathbb{Z}$ with $(k,q)=1$ such that $\chi(k)\neq 1$. Note that $$\sum_{a=1}^{q}\chi(a)=\sum_{\substack{1\leq a\leq q\\ (a,q)=1}}\chi(a)$$ since $\chi(a)=0$ if $(a,q)>1$. Then $$\chi(k)\sum_{a=1}^{q}\chi(a)=\sum_{\substack{1\leq a\leq q\\ (a,q)=1}}\chi(ka)=\sum_{a=1}^{q}\chi(a). $$ Where does the right side of the last equation come from? I found a reference that says,
Observe that, if $a$ runs through these values, then so does $b=ak$, after reducing modulo $q$. Therefore $$\chi(k)\sum_{a=1}^{q}\chi(a)=\sum_{\substack{1\leq a\leq q\\ (a,q)=1}}\chi(ka)=\sum_{\substack{1\leq b\leq q\\ (b,q)=1}}\chi(b).$$
I do not understand this well. My understanding is as follows: Let $L_q=\{a:1\leq a\leq q \wedge (a,q)=1\}$. Suppose that $(k,q)=1$. The claim is, if $a\in L_q$, then $ka\in L_q$. It is clear that $(ka,q)=1$, but I do not know if $ka$ lies in $[1,q]$.