I'm proving that computing square roots in $\mathbb{Z}_{pq}$ implies factoring $n = pq$ with $p,q$ primes. The solution give you an algorithm:
repeat
1. pick y from {1,...,n-1}
2. x = y^2 mod n
3. y' = random square root of x
until y' != y and y' != - y mod n
Basically the algorithm calculates the four square roots of some number x and then takes $p = gcd(y'-y,n)$. But I'm stuck at this point. Why can we guarantee that $p = gcd(y'-y,n)$?
What my note say is that $y − y'$ is zero modulo one of the two factors but not modulo the other.
Let $p$ and $q$ be distinct primes.
Suppose you have found two numbers $a, b$ such that $$\tag{formula} a^{2} \equiv b^{2} \pmod{n}, $$ but $$\tag{assumption} a \not\equiv \pm b \pmod{n}. $$ The first equation tells you that $$ n \mid a^{2} - b^{2} = (a - b) (a + b). $$ Consider $d = \gcd(n, a - b)$. As a divisor of $n$, it could be $1, p, q, n$. If it is $p, q$ we have factored $n$. So can we exclude it is $1$ or $n$?
If $\gcd(n, a - b) = n$, then $n \mid a - b$, so $a \equiv b \pmod{n}$, against (assumption).
If $\gcd(n, a - b) = 1$, then (formula) yields $n \mid a + b$, so $a \equiv -b \pmod{n}$, against (assumption).