I am looking for a top-down overarching or superseding theory in number theory (or at least a proof) that explains the following patterns:
Take positive integers $n,k$ and examine successive remainders (constant modulo): $$n\mod k,n^2 \mod k,n^3 \mod k,n^4 \mod k,\ldots,$$ for some positive integer $k$.
The pattern is appears to always be periodic (at least eventually; in the case for $n=6,k=8$, the pattern is 6,4,0,0,0,0,0,...), and the period of those cycles varies for different combinations $n$ and $k$.
After examining different combinations via a Python script, I really can't make head or tails of why the patterns occur.
For example: $n=3,k=4$ yields a pattern of 3,1,3,1,....
For $n=5,k=7$ yields the repeating pattern of 5, 4, 6, 2, 3, 1.
Thanks