Is there an efficient way to compute the square root of modulo prime?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












Is there a reasonably simple way to find the square root of $a$ modulo $p$ where $p$ is an odd prime?
If the odd prime is small number it seems you can do this by brute force. HOwever if we want to solve something like x^2=2 mod 103 (whose solution is 38 and 65 mod 103) is pretty cumbersome because we have a non-linear Diophantine equation x^2=2+101y. Is there an efficient and quick method to solve something of this kind? If I try primitive roots then the first primitive root is 5 not 2 so that does not help.







share|cite|improve this question

















  • 1




    Please see here on MO.
    – TheSimpliFire
    Jul 15 at 11:22






  • 1




    Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
    – CJD
    Jul 15 at 11:47











  • @cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
    – Oscar Lanzi
    Jul 15 at 12:33











  • Tonelli–Shanks algorithm
    – Count Iblis
    Jul 15 at 14:36







  • 1




    The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
    – hardmath
    Jul 15 at 19:20














up vote
2
down vote

favorite
1












Is there a reasonably simple way to find the square root of $a$ modulo $p$ where $p$ is an odd prime?
If the odd prime is small number it seems you can do this by brute force. HOwever if we want to solve something like x^2=2 mod 103 (whose solution is 38 and 65 mod 103) is pretty cumbersome because we have a non-linear Diophantine equation x^2=2+101y. Is there an efficient and quick method to solve something of this kind? If I try primitive roots then the first primitive root is 5 not 2 so that does not help.







share|cite|improve this question

















  • 1




    Please see here on MO.
    – TheSimpliFire
    Jul 15 at 11:22






  • 1




    Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
    – CJD
    Jul 15 at 11:47











  • @cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
    – Oscar Lanzi
    Jul 15 at 12:33











  • Tonelli–Shanks algorithm
    – Count Iblis
    Jul 15 at 14:36







  • 1




    The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
    – hardmath
    Jul 15 at 19:20












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





Is there a reasonably simple way to find the square root of $a$ modulo $p$ where $p$ is an odd prime?
If the odd prime is small number it seems you can do this by brute force. HOwever if we want to solve something like x^2=2 mod 103 (whose solution is 38 and 65 mod 103) is pretty cumbersome because we have a non-linear Diophantine equation x^2=2+101y. Is there an efficient and quick method to solve something of this kind? If I try primitive roots then the first primitive root is 5 not 2 so that does not help.







share|cite|improve this question













Is there a reasonably simple way to find the square root of $a$ modulo $p$ where $p$ is an odd prime?
If the odd prime is small number it seems you can do this by brute force. HOwever if we want to solve something like x^2=2 mod 103 (whose solution is 38 and 65 mod 103) is pretty cumbersome because we have a non-linear Diophantine equation x^2=2+101y. Is there an efficient and quick method to solve something of this kind? If I try primitive roots then the first primitive root is 5 not 2 so that does not help.









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 15 at 18:46
























asked Jul 15 at 11:07









matqkks

1,09511631




1,09511631







  • 1




    Please see here on MO.
    – TheSimpliFire
    Jul 15 at 11:22






  • 1




    Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
    – CJD
    Jul 15 at 11:47











  • @cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
    – Oscar Lanzi
    Jul 15 at 12:33











  • Tonelli–Shanks algorithm
    – Count Iblis
    Jul 15 at 14:36







  • 1




    The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
    – hardmath
    Jul 15 at 19:20












  • 1




    Please see here on MO.
    – TheSimpliFire
    Jul 15 at 11:22






  • 1




    Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
    – CJD
    Jul 15 at 11:47











  • @cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
    – Oscar Lanzi
    Jul 15 at 12:33











  • Tonelli–Shanks algorithm
    – Count Iblis
    Jul 15 at 14:36







  • 1




    The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
    – hardmath
    Jul 15 at 19:20







1




1




Please see here on MO.
– TheSimpliFire
Jul 15 at 11:22




Please see here on MO.
– TheSimpliFire
Jul 15 at 11:22




1




1




Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
– CJD
Jul 15 at 11:47





Do you know how to do this if p is 3 mod 4? In that case it's very easy: just raise a to the (p+1)/4 modulo p. (Of course this only works if a has a square root mod p.) The above link seems to be showing that it's always efficient, but it is definitely more complicated in the case that p is 1 mod 4.
– CJD
Jul 15 at 11:47













@cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
– Oscar Lanzi
Jul 15 at 12:33





@cjd, fyi. What if you try tovtwke the square root of a residue $r bmod p$ that isn't a quadratic residue? With $pequiv 3bmod 4$ the $r^(p+1)/4$ formula gives instead a square root of $-r$.
– Oscar Lanzi
Jul 15 at 12:33













Tonelli–Shanks algorithm
– Count Iblis
Jul 15 at 14:36





Tonelli–Shanks algorithm
– Count Iblis
Jul 15 at 14:36





1




1




The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
– hardmath
Jul 15 at 19:20




The easy case $p equiv 3 bmod 4$ has been discussed in previous Questions, but there is perhaps room on Math.SE for a comprehensive Answer for $p equiv 1 bmod 4$ (not just the link to the Wikipedia article, as there are competing algorithms).
– hardmath
Jul 15 at 19:20










2 Answers
2






active

oldest

votes

















up vote
3
down vote













Partial answer:



If $p=4n-1$, then let $b = a^fracp+14$. Then $b^2=a^fracp+12=a^fracp-12aequiv a$ because of Euler's criterion.






share|cite|improve this answer




























    up vote
    1
    down vote













    Let $p$ be an odd prime and we can say whether an integer $a$, $ane0(mboxmod)p,$ has a square root mod $p$ or not by
    $$mboxa is begincasesmboxa quadratic residue if $a^fracp-12equiv 1(mboxmod p)$ \mboxa quadratic nonresidue if $a^fracp-12equiv -1(mboxmod p)$endcases$$






    share|cite|improve this answer



















    • 2




      That doesn't compute the square root.
      – Lord Shark the Unknown
      Jul 15 at 11:55










    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "69"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2852403%2fis-there-an-efficient-way-to-compute-the-square-root-of-modulo-prime%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    Partial answer:



    If $p=4n-1$, then let $b = a^fracp+14$. Then $b^2=a^fracp+12=a^fracp-12aequiv a$ because of Euler's criterion.






    share|cite|improve this answer

























      up vote
      3
      down vote













      Partial answer:



      If $p=4n-1$, then let $b = a^fracp+14$. Then $b^2=a^fracp+12=a^fracp-12aequiv a$ because of Euler's criterion.






      share|cite|improve this answer























        up vote
        3
        down vote










        up vote
        3
        down vote









        Partial answer:



        If $p=4n-1$, then let $b = a^fracp+14$. Then $b^2=a^fracp+12=a^fracp-12aequiv a$ because of Euler's criterion.






        share|cite|improve this answer













        Partial answer:



        If $p=4n-1$, then let $b = a^fracp+14$. Then $b^2=a^fracp+12=a^fracp-12aequiv a$ because of Euler's criterion.







        share|cite|improve this answer













        share|cite|improve this answer



        share|cite|improve this answer











        answered Jul 15 at 12:09









        lhf

        156k9160367




        156k9160367




















            up vote
            1
            down vote













            Let $p$ be an odd prime and we can say whether an integer $a$, $ane0(mboxmod)p,$ has a square root mod $p$ or not by
            $$mboxa is begincasesmboxa quadratic residue if $a^fracp-12equiv 1(mboxmod p)$ \mboxa quadratic nonresidue if $a^fracp-12equiv -1(mboxmod p)$endcases$$






            share|cite|improve this answer



















            • 2




              That doesn't compute the square root.
              – Lord Shark the Unknown
              Jul 15 at 11:55














            up vote
            1
            down vote













            Let $p$ be an odd prime and we can say whether an integer $a$, $ane0(mboxmod)p,$ has a square root mod $p$ or not by
            $$mboxa is begincasesmboxa quadratic residue if $a^fracp-12equiv 1(mboxmod p)$ \mboxa quadratic nonresidue if $a^fracp-12equiv -1(mboxmod p)$endcases$$






            share|cite|improve this answer



















            • 2




              That doesn't compute the square root.
              – Lord Shark the Unknown
              Jul 15 at 11:55












            up vote
            1
            down vote










            up vote
            1
            down vote









            Let $p$ be an odd prime and we can say whether an integer $a$, $ane0(mboxmod)p,$ has a square root mod $p$ or not by
            $$mboxa is begincasesmboxa quadratic residue if $a^fracp-12equiv 1(mboxmod p)$ \mboxa quadratic nonresidue if $a^fracp-12equiv -1(mboxmod p)$endcases$$






            share|cite|improve this answer















            Let $p$ be an odd prime and we can say whether an integer $a$, $ane0(mboxmod)p,$ has a square root mod $p$ or not by
            $$mboxa is begincasesmboxa quadratic residue if $a^fracp-12equiv 1(mboxmod p)$ \mboxa quadratic nonresidue if $a^fracp-12equiv -1(mboxmod p)$endcases$$







            share|cite|improve this answer















            share|cite|improve this answer



            share|cite|improve this answer








            edited Jul 15 at 12:02


























            answered Jul 15 at 11:48









            Key Flex

            4,406525




            4,406525







            • 2




              That doesn't compute the square root.
              – Lord Shark the Unknown
              Jul 15 at 11:55












            • 2




              That doesn't compute the square root.
              – Lord Shark the Unknown
              Jul 15 at 11:55







            2




            2




            That doesn't compute the square root.
            – Lord Shark the Unknown
            Jul 15 at 11:55




            That doesn't compute the square root.
            – Lord Shark the Unknown
            Jul 15 at 11:55












             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2852403%2fis-there-an-efficient-way-to-compute-the-square-root-of-modulo-prime%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What is the equation of a 3D cone with generalised tilt?

            Color the edges and diagonals of a regular polygon

            Relationship between determinant of matrix and determinant of adjoint?