In this section we describe the Rabin-Shallit polynomial-time
Las Vegas algorithm to represent a given prime of the form
as the sum of two squares.
We know that
is a quadratic residue in
for
,
i.e. there exists
such that
. Our first task
is to find such
? This is equivalent to factoring the polynomial
.
Divisibility, primes, g.c.d. are defined among Gaussian integers the same way as among integers. (Recall: by definition, the greatest common divisor is not ``largest'' among the common divisors but one that is a common multiple of all common divisors. So its existence is not evident.)
There are four units (numbers dividing
) among Gaussian integers,
, and
.
Let us take a look at Gaussian primes.
and
are not primes in
(because
) but
remains a prime.
The algorithm
Let
. By factoring the polynomial
over
, we found, in Las Vegas polynomial time,
and integer
such that
.
Now
. Since
(
,
unknown)
and
is a prime in
, it follows that
divides either
or
(but not both - why?).
Therefore
splits
: if
then
.
Otherwise,
. In either case, we find
using Euclid's algorithm in
.