If you have $a,b\in\mathbb{N}$ such that $a^2+b^2=M$, are there other natural numbers $c,d$ such that $c^2+d^2=M$? If so, is there an algorithm for generating such pairs or an equation relating them to $a$ and $b$? I tried messing around with a few ideas using $\mathbb{Z[i]}$, but didn't really get anywhere.