I think "But then the string consists of only one character repeated over and over, hence we can compress it to a string of size $1$ ..." is false. Shouldn't it be written: "But then the string consists of $gcd(p, k)$ characters repeated over and over, hence we can compress it to a string of size $gcd(p, k)$, and since it divides $p$ it also divides $n$."
Example: k = 4, n = 12, p = 6.