0

Given the equation y^2=x^3+2*x+4 mod 7 i want to find all possible solutions with x and y being in the range of 0 to 6. I have written the following program:

for  (int y=0;y<7;y++)
{
  for  (int x=0;x<7;x++)
{

    if ((x^3+5*x+4)%7==(y^2)%7)
    {

        cout<<"("<<x<<","<<y<<")"<<endl;
    }
}  
}

However, the output of this program is wrong. For example, the program prints out (4,1), however this does not satisfy the equation. How can i fix this?

1 Answers1

0

I think the problem is that x^3 and y^2 are not power operation, it is xor operation indeed, so, you can use x*x*x and y*y instead:

    for  (int y=0;y<7;y++)
    {
        for  (int x=0;x<7;x++)
        {

            if ((x*x*x+5*x+4)%7==(y*y)%7)
            {

                std::cout<<"("<<x<<","<<y<<")"<<std::endl;
            }
        }
    }
}
Tiger Yu
  • 744
  • 3
  • 5