Skip to content

Commit

Permalink
Don't try to compute square root of non-square.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskeller committed Jul 26, 2017
1 parent 58b6541 commit 9256e08
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Math/bigint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bigint sqrRootMod(const bigint& a,const bigint& p)
{
bigint ans;
if (a==0) { ans=0; return ans; }
if (mpz_legendre(a.get_mpz_t(), p.get_mpz_t()) != 1)
throw runtime_error("cannot compute square root of non-square");
if (mpz_tstbit(p.get_mpz_t(),1)==1)
{ // First do case with p=3 mod 4
bigint exp=(p+1)/4;
Expand Down

0 comments on commit 9256e08

Please sign in to comment.