How to verify if g is a generator for p? Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How large should a Diffie-Hellman p be?Why is it impractical to generate a semiprime dictionary?Help with example RSA problemObtaining Diffie-Hellman generator“Prime conspiracy”'s effect on cryptographyHow is it possible that $g^q equiv 1 pmod p$ for a generator g?What algorithm does .NET use to generate primes for RSA and how can I verify it?How to find a generator g for a large prime p?RSA finding p and q integer with conditionEl-Gamal like encryption, how can i guess the key?

Why WordPress uses 4 tables to manage terms

How would I use different systems of magic when they are capable of the same effects?

How to keep bees out of canned beverages?

How to avoid introduction cliches

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

What was Apollo 13's "Little Jolt" after MECO?

What to do with someone that cheated their way through university and a PhD program?

Does Feeblemind produce an ongoing magical effect that can be dispelled?

How to open locks without disable device?

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Implementing 3DES algorithm in Java: is my code secure?

Why doesn't the standard consider a template constructor as a copy constructor?

Check if a string is entirely made of the same substring

How to not starve gigantic beasts

How to translate "red flag" into Spanish?

Is Diceware more secure than a long passphrase?

Is there any pythonic way to find average of specific tuple elements in array?

What's parked in Mil Moscow helicopter plant?

Approximating integral with small parameter

Multiple options vs single option UI

Can we hide a text first in a picture and then hide that image again in one more image?

Putting Ant-Man on house arrest

What is it called when you ride around on your front wheel?

What is the term for a person whose job is to place products on shelves in stores?



How to verify if g is a generator for p?



Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How large should a Diffie-Hellman p be?Why is it impractical to generate a semiprime dictionary?Help with example RSA problemObtaining Diffie-Hellman generator“Prime conspiracy”'s effect on cryptographyHow is it possible that $g^q equiv 1 pmod p$ for a generator g?What algorithm does .NET use to generate primes for RSA and how can I verify it?How to find a generator g for a large prime p?RSA finding p and q integer with conditionEl-Gamal like encryption, how can i guess the key?










4












$begingroup$


For learning purpose, supposed I have a 16-digit prime which is 2685735182215187, how do I verify if g is a generator? (p is supposedly a special kind of prime)










share|improve this question









$endgroup$







  • 2




    $begingroup$
    The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
    $endgroup$
    – puzzlepalace
    Mar 26 at 17:45










  • $begingroup$
    @puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
    $endgroup$
    – Ken
    Mar 26 at 18:43










  • $begingroup$
    You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
    $endgroup$
    – puzzlepalace
    Mar 26 at 18:54










  • $begingroup$
    @puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
    $endgroup$
    – Ken
    Mar 26 at 19:03










  • $begingroup$
    @puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
    $endgroup$
    – Ken
    Mar 26 at 19:05















4












$begingroup$


For learning purpose, supposed I have a 16-digit prime which is 2685735182215187, how do I verify if g is a generator? (p is supposedly a special kind of prime)










share|improve this question









$endgroup$







  • 2




    $begingroup$
    The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
    $endgroup$
    – puzzlepalace
    Mar 26 at 17:45










  • $begingroup$
    @puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
    $endgroup$
    – Ken
    Mar 26 at 18:43










  • $begingroup$
    You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
    $endgroup$
    – puzzlepalace
    Mar 26 at 18:54










  • $begingroup$
    @puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
    $endgroup$
    – Ken
    Mar 26 at 19:03










  • $begingroup$
    @puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
    $endgroup$
    – Ken
    Mar 26 at 19:05













4












4








4





$begingroup$


For learning purpose, supposed I have a 16-digit prime which is 2685735182215187, how do I verify if g is a generator? (p is supposedly a special kind of prime)










share|improve this question









$endgroup$




For learning purpose, supposed I have a 16-digit prime which is 2685735182215187, how do I verify if g is a generator? (p is supposedly a special kind of prime)







rsa prime-numbers elgamal-encryption






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 16:30









KenKen

362




362







  • 2




    $begingroup$
    The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
    $endgroup$
    – puzzlepalace
    Mar 26 at 17:45










  • $begingroup$
    @puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
    $endgroup$
    – Ken
    Mar 26 at 18:43










  • $begingroup$
    You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
    $endgroup$
    – puzzlepalace
    Mar 26 at 18:54










  • $begingroup$
    @puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
    $endgroup$
    – Ken
    Mar 26 at 19:03










  • $begingroup$
    @puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
    $endgroup$
    – Ken
    Mar 26 at 19:05












  • 2




    $begingroup$
    The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
    $endgroup$
    – puzzlepalace
    Mar 26 at 17:45










  • $begingroup$
    @puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
    $endgroup$
    – Ken
    Mar 26 at 18:43










  • $begingroup$
    You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
    $endgroup$
    – puzzlepalace
    Mar 26 at 18:54










  • $begingroup$
    @puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
    $endgroup$
    – Ken
    Mar 26 at 19:03










  • $begingroup$
    @puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
    $endgroup$
    – Ken
    Mar 26 at 19:05







2




2




$begingroup$
The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
$endgroup$
– puzzlepalace
Mar 26 at 17:45




$begingroup$
The special kind of prime that you have is called a safe prime. it's a prime of the form $p = 2q + 1$ where $q$ is also prime (as shown by poncho's answer).
$endgroup$
– puzzlepalace
Mar 26 at 17:45












$begingroup$
@puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
$endgroup$
– Ken
Mar 26 at 18:43




$begingroup$
@puzzlepalace sorry, I'm still confused about q. Where do I actually get the q?
$endgroup$
– Ken
Mar 26 at 18:43












$begingroup$
You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
$endgroup$
– puzzlepalace
Mar 26 at 18:54




$begingroup$
You can derive $q$ from $p$. In other words, to check if $p$ is a safe prime, you check if $q = fracp-12$ is also prime.
$endgroup$
– puzzlepalace
Mar 26 at 18:54












$begingroup$
@puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
$endgroup$
– Ken
Mar 26 at 19:03




$begingroup$
@puzzlepalace Thank you for your swift reply. I have computed and checked q=(p-1)/2 and my program returns true (it is indeed a prime). So I'm safe to say that q is also a prime, which means that p is a special kind of prime.
$endgroup$
– Ken
Mar 26 at 19:03












$begingroup$
@puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
$endgroup$
– Ken
Mar 26 at 19:05




$begingroup$
@puzzlepalace However, I'm still confused about g. I have computed g^(p-1)/2 mod p and g^p-1/(p-1/2) like what poncho has mentioned. The first output is 1342867591052455, and the second output is 0. I'm a little confused about these numbers, do they mean that g is a generator?
$endgroup$
– Ken
Mar 26 at 19:05










3 Answers
3






active

oldest

votes


















6












$begingroup$

Steps:



  • Factor $p-1$, that is, find the primes which, multiplied together, produce $p-1$. In your case, $2685735182215186 = 2 times 1342867591107593$


  • For each prime factor $q$ of $p-1$, verify that $g^(p-1)/q notequiv 1pmod p$


If every such $q$ verifies (that is, they were all not 1), then $g$ is a generator.






share|improve this answer









$endgroup$












  • $begingroup$
    Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
    $endgroup$
    – Ken
    Mar 26 at 17:13










  • $begingroup$
    @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
    $endgroup$
    – poncho
    Mar 26 at 17:18











  • $begingroup$
    Thank you so much @poncho
    $endgroup$
    – Ken
    Mar 26 at 17:24










  • $begingroup$
    @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
    $endgroup$
    – Ilmari Karonen
    Mar 26 at 20:07







  • 1




    $begingroup$
    What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
    $endgroup$
    – orlp
    Mar 26 at 23:30


















5












$begingroup$

In general, proving that $g$ is a primitive root (often called a generator) of a cyclic group is fairly simple. Note this holds true for non prime modulo as well



Step 1:



Verify that $0leqslant g lt p$ and $(g,p)=1$



In other words, verify that $g$ is less than p but greater than or equal to 0, and that $g$ and $p$ are coprime.



Where $g$ is the element of the group in question and p is the modulus being used (or: $mathbbZ_p$).



Step 2:



Calculate $phi(p)$ where $phi$ is the Totient Function. If it happens that $p$ is prime, $phi(p)=p-1$



Then break $phi(p)$ into it's prime factors such that $phi(p)=prodlimits_iq_i^r_i$ Where each $q_i$ is a prime factor and $r_i$ is the power that prime factor is raised to.



(This notation simply implies that $phi(p)$ is to be broken down into it's prime factors $q_i$ such that $phi(p)=q_1^r_1times q_2^r_2times ...$)



Verify that $g^phi(p)/q_inotequiv 1 (mod p)$ $forall q_i$



Ignore the power $r_i$ for this calculation.



Assuming these conditions are met, $g$ is a generator of $mathbbZ_p$.




Example:



Let $p=101$, $g=2$.



Step 1:



$0leqslant 2 lt 101$ $checkmark$



and



$(2,101) = 1$ $checkmark $



Which can be checked using the Extended Euclidean Algorithm if $p$ is not prime (however, 101 is prime, so 2 is most definitely coprime to it).



Step 2



Calculate $phi(p)=p-1=phi(101)=101-1=100$ (Assuming $p$ is prime).



Now that we know $phi(101)=100$, we can break it down into it's prime factors. Check that:



$100=2^2times5^2$



This means that our $q_1=2, q_2=5$. Remember that we ignore the powers $r_i$ of each of the prime factors for our computations.



Finally, we check:



$2^phi(101)/q_1=2^(101-1)/2=2^50equiv100notequiv1(mod 101)checkmark$
$2^phi(101)/q_2=2^(101-1)/5=2^20equiv95notequiv1(mod 101)checkmark$



$therefore g$ is a generator $mod 101$.



(Read: therefore $g$ is a generator $mod 101$.)



Note that this process is to be done $forall q_i$, in our case there were only two.



(Read: note that this process is to be done for all $q_i$...)




In your example, and in practical examples, $p$ is very large. First, confirming that $p$ is prime can be difficult. Second, factorizing $phi(p)$ into it's prme factors can be quite difficult. I recommend implementing an algorithm to help you, such as Pollard's rho algorithm (although there are others that'll work, like trivial division).






share|improve this answer











$endgroup$












  • $begingroup$
    Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
    $endgroup$
    – Ken
    Mar 27 at 6:02











  • $begingroup$
    @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
    $endgroup$
    – TryingToPassCollege
    Mar 27 at 13:47










  • $begingroup$
    Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
    $endgroup$
    – poncho
    Mar 27 at 16:03



















1












$begingroup$

$p = 2685735182215187$ is prime, and $p - 1 = 2q$ where $q = 1342867591107593$ is prime, so the only possible orders of $g$ are $1, 2, q, 2q$, corresponding respectively to




  • $g equiv 1 pmod p$,


  • $g equiv -1 pmod p$,


  • $g$ is a nontrivial quadratic residue modulo $p$, i.e. there is some $h notin 0,pm1$ such that $g equiv h^2 pmod p$, and


  • $g$ is a nontrivial quadratic nonresidue modulo $p$, which in this case generates the whole group.

If $g$ is neither $1$ nor $-1$, it suffices to compute the Legendre symbol of $g$, $$(g|p) := g^(p - 1)/2 bmod p = g^q bmod p,$$ which is 1 if $g$ is a quadratic residue and 0 or -1 if it is not. Obviously you can compute $g^q bmod p$ directly, as in poncho's answer which applies more generally, but for many values of $g$, there are special cases which you can test much more easily by the quadratic reciprocity theorem, that, for distinct odd primes $a$ and $b$, $(a|b) = -(b|a)$ if $a equiv b equiv 3 pmod 4$, whereas $(a|b) = (b|a)$ if either $a equiv 1 pmod 4$ or $b equiv 1 pmod 4$.




  • $3 equiv p equiv 3 pmod 4$, so $(3|p) = -(p|3) = -p^(3 - 1)/2 bmod 3 = -p^1 bmod 3 = 1$, so 3 is a quadratic residue and thus is not a generator of the whole group.


  • $5 equiv 1 pmod 4$, so $(5|p) = (p|5) = p^(5 - 1)/2 bmod 5 = p^2 bmod 5 = 4 bmod 5 = -1$, so 5 is a quadratic nonresidue and thus is a generator of the whole group.

  • The second supplement to the quadratic reciprocity theorem is that $g = 2$ is a quadratic residue modulo $p$ if and only if $p equiv pm 1 pmod 8$. In this case, $p equiv 3 pmod 8$, so 2 is a quadratic nonresidue and thus is a generator of the whole group.





share|improve this answer











$endgroup$













    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "281"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    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%2fcrypto.stackexchange.com%2fquestions%2f68317%2fhow-to-verify-if-g-is-a-generator-for-p%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6












    $begingroup$

    Steps:



    • Factor $p-1$, that is, find the primes which, multiplied together, produce $p-1$. In your case, $2685735182215186 = 2 times 1342867591107593$


    • For each prime factor $q$ of $p-1$, verify that $g^(p-1)/q notequiv 1pmod p$


    If every such $q$ verifies (that is, they were all not 1), then $g$ is a generator.






    share|improve this answer









    $endgroup$












    • $begingroup$
      Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
      $endgroup$
      – Ken
      Mar 26 at 17:13










    • $begingroup$
      @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
      $endgroup$
      – poncho
      Mar 26 at 17:18











    • $begingroup$
      Thank you so much @poncho
      $endgroup$
      – Ken
      Mar 26 at 17:24










    • $begingroup$
      @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
      $endgroup$
      – Ilmari Karonen
      Mar 26 at 20:07







    • 1




      $begingroup$
      What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
      $endgroup$
      – orlp
      Mar 26 at 23:30















    6












    $begingroup$

    Steps:



    • Factor $p-1$, that is, find the primes which, multiplied together, produce $p-1$. In your case, $2685735182215186 = 2 times 1342867591107593$


    • For each prime factor $q$ of $p-1$, verify that $g^(p-1)/q notequiv 1pmod p$


    If every such $q$ verifies (that is, they were all not 1), then $g$ is a generator.






    share|improve this answer









    $endgroup$












    • $begingroup$
      Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
      $endgroup$
      – Ken
      Mar 26 at 17:13










    • $begingroup$
      @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
      $endgroup$
      – poncho
      Mar 26 at 17:18











    • $begingroup$
      Thank you so much @poncho
      $endgroup$
      – Ken
      Mar 26 at 17:24










    • $begingroup$
      @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
      $endgroup$
      – Ilmari Karonen
      Mar 26 at 20:07







    • 1




      $begingroup$
      What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
      $endgroup$
      – orlp
      Mar 26 at 23:30













    6












    6








    6





    $begingroup$

    Steps:



    • Factor $p-1$, that is, find the primes which, multiplied together, produce $p-1$. In your case, $2685735182215186 = 2 times 1342867591107593$


    • For each prime factor $q$ of $p-1$, verify that $g^(p-1)/q notequiv 1pmod p$


    If every such $q$ verifies (that is, they were all not 1), then $g$ is a generator.






    share|improve this answer









    $endgroup$



    Steps:



    • Factor $p-1$, that is, find the primes which, multiplied together, produce $p-1$. In your case, $2685735182215186 = 2 times 1342867591107593$


    • For each prime factor $q$ of $p-1$, verify that $g^(p-1)/q notequiv 1pmod p$


    If every such $q$ verifies (that is, they were all not 1), then $g$ is a generator.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 26 at 16:33









    ponchoponcho

    94.7k2151248




    94.7k2151248











    • $begingroup$
      Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
      $endgroup$
      – Ken
      Mar 26 at 17:13










    • $begingroup$
      @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
      $endgroup$
      – poncho
      Mar 26 at 17:18











    • $begingroup$
      Thank you so much @poncho
      $endgroup$
      – Ken
      Mar 26 at 17:24










    • $begingroup$
      @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
      $endgroup$
      – Ilmari Karonen
      Mar 26 at 20:07







    • 1




      $begingroup$
      What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
      $endgroup$
      – orlp
      Mar 26 at 23:30
















    • $begingroup$
      Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
      $endgroup$
      – Ken
      Mar 26 at 17:13










    • $begingroup$
      @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
      $endgroup$
      – poncho
      Mar 26 at 17:18











    • $begingroup$
      Thank you so much @poncho
      $endgroup$
      – Ken
      Mar 26 at 17:24










    • $begingroup$
      @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
      $endgroup$
      – Ilmari Karonen
      Mar 26 at 20:07







    • 1




      $begingroup$
      What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
      $endgroup$
      – orlp
      Mar 26 at 23:30















    $begingroup$
    Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
    $endgroup$
    – Ken
    Mar 26 at 17:13




    $begingroup$
    Hey @poncho thanks. I do not understand "For each prime factor q of p−1, verify that g(p−1)/q≢1(mod p)" Is there anyway you can explain it simpler?
    $endgroup$
    – Ken
    Mar 26 at 17:13












    $begingroup$
    @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
    $endgroup$
    – poncho
    Mar 26 at 17:18





    $begingroup$
    @Ken: Compute $g^2685735182215186/2 bmod p$. Compute $g^2685735182215186/1342867591107593 bmod p$. If they are both something other than 1, then $g$ is a generator
    $endgroup$
    – poncho
    Mar 26 at 17:18













    $begingroup$
    Thank you so much @poncho
    $endgroup$
    – Ken
    Mar 26 at 17:24




    $begingroup$
    Thank you so much @poncho
    $endgroup$
    – Ken
    Mar 26 at 17:24












    $begingroup$
    @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
    $endgroup$
    – Ilmari Karonen
    Mar 26 at 20:07





    $begingroup$
    @Ken: Java's long type has 64 bits; it's not going to be able to store $2^1342867591107593$ without wrapping around. You will need to either switch to BigIntegers (in which case you really should use BigInteger::modPow) or implement a modular exponentiation algorithm yourself.
    $endgroup$
    – Ilmari Karonen
    Mar 26 at 20:07





    1




    1




    $begingroup$
    What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
    $endgroup$
    – orlp
    Mar 26 at 23:30




    $begingroup$
    What if factoring $p - 1$ is unfeasible? Is it then impossible to verify or are there other techniques you can apply?
    $endgroup$
    – orlp
    Mar 26 at 23:30











    5












    $begingroup$

    In general, proving that $g$ is a primitive root (often called a generator) of a cyclic group is fairly simple. Note this holds true for non prime modulo as well



    Step 1:



    Verify that $0leqslant g lt p$ and $(g,p)=1$



    In other words, verify that $g$ is less than p but greater than or equal to 0, and that $g$ and $p$ are coprime.



    Where $g$ is the element of the group in question and p is the modulus being used (or: $mathbbZ_p$).



    Step 2:



    Calculate $phi(p)$ where $phi$ is the Totient Function. If it happens that $p$ is prime, $phi(p)=p-1$



    Then break $phi(p)$ into it's prime factors such that $phi(p)=prodlimits_iq_i^r_i$ Where each $q_i$ is a prime factor and $r_i$ is the power that prime factor is raised to.



    (This notation simply implies that $phi(p)$ is to be broken down into it's prime factors $q_i$ such that $phi(p)=q_1^r_1times q_2^r_2times ...$)



    Verify that $g^phi(p)/q_inotequiv 1 (mod p)$ $forall q_i$



    Ignore the power $r_i$ for this calculation.



    Assuming these conditions are met, $g$ is a generator of $mathbbZ_p$.




    Example:



    Let $p=101$, $g=2$.



    Step 1:



    $0leqslant 2 lt 101$ $checkmark$



    and



    $(2,101) = 1$ $checkmark $



    Which can be checked using the Extended Euclidean Algorithm if $p$ is not prime (however, 101 is prime, so 2 is most definitely coprime to it).



    Step 2



    Calculate $phi(p)=p-1=phi(101)=101-1=100$ (Assuming $p$ is prime).



    Now that we know $phi(101)=100$, we can break it down into it's prime factors. Check that:



    $100=2^2times5^2$



    This means that our $q_1=2, q_2=5$. Remember that we ignore the powers $r_i$ of each of the prime factors for our computations.



    Finally, we check:



    $2^phi(101)/q_1=2^(101-1)/2=2^50equiv100notequiv1(mod 101)checkmark$
    $2^phi(101)/q_2=2^(101-1)/5=2^20equiv95notequiv1(mod 101)checkmark$



    $therefore g$ is a generator $mod 101$.



    (Read: therefore $g$ is a generator $mod 101$.)



    Note that this process is to be done $forall q_i$, in our case there were only two.



    (Read: note that this process is to be done for all $q_i$...)




    In your example, and in practical examples, $p$ is very large. First, confirming that $p$ is prime can be difficult. Second, factorizing $phi(p)$ into it's prme factors can be quite difficult. I recommend implementing an algorithm to help you, such as Pollard's rho algorithm (although there are others that'll work, like trivial division).






    share|improve this answer











    $endgroup$












    • $begingroup$
      Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
      $endgroup$
      – Ken
      Mar 27 at 6:02











    • $begingroup$
      @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
      $endgroup$
      – TryingToPassCollege
      Mar 27 at 13:47










    • $begingroup$
      Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
      $endgroup$
      – poncho
      Mar 27 at 16:03
















    5












    $begingroup$

    In general, proving that $g$ is a primitive root (often called a generator) of a cyclic group is fairly simple. Note this holds true for non prime modulo as well



    Step 1:



    Verify that $0leqslant g lt p$ and $(g,p)=1$



    In other words, verify that $g$ is less than p but greater than or equal to 0, and that $g$ and $p$ are coprime.



    Where $g$ is the element of the group in question and p is the modulus being used (or: $mathbbZ_p$).



    Step 2:



    Calculate $phi(p)$ where $phi$ is the Totient Function. If it happens that $p$ is prime, $phi(p)=p-1$



    Then break $phi(p)$ into it's prime factors such that $phi(p)=prodlimits_iq_i^r_i$ Where each $q_i$ is a prime factor and $r_i$ is the power that prime factor is raised to.



    (This notation simply implies that $phi(p)$ is to be broken down into it's prime factors $q_i$ such that $phi(p)=q_1^r_1times q_2^r_2times ...$)



    Verify that $g^phi(p)/q_inotequiv 1 (mod p)$ $forall q_i$



    Ignore the power $r_i$ for this calculation.



    Assuming these conditions are met, $g$ is a generator of $mathbbZ_p$.




    Example:



    Let $p=101$, $g=2$.



    Step 1:



    $0leqslant 2 lt 101$ $checkmark$



    and



    $(2,101) = 1$ $checkmark $



    Which can be checked using the Extended Euclidean Algorithm if $p$ is not prime (however, 101 is prime, so 2 is most definitely coprime to it).



    Step 2



    Calculate $phi(p)=p-1=phi(101)=101-1=100$ (Assuming $p$ is prime).



    Now that we know $phi(101)=100$, we can break it down into it's prime factors. Check that:



    $100=2^2times5^2$



    This means that our $q_1=2, q_2=5$. Remember that we ignore the powers $r_i$ of each of the prime factors for our computations.



    Finally, we check:



    $2^phi(101)/q_1=2^(101-1)/2=2^50equiv100notequiv1(mod 101)checkmark$
    $2^phi(101)/q_2=2^(101-1)/5=2^20equiv95notequiv1(mod 101)checkmark$



    $therefore g$ is a generator $mod 101$.



    (Read: therefore $g$ is a generator $mod 101$.)



    Note that this process is to be done $forall q_i$, in our case there were only two.



    (Read: note that this process is to be done for all $q_i$...)




    In your example, and in practical examples, $p$ is very large. First, confirming that $p$ is prime can be difficult. Second, factorizing $phi(p)$ into it's prme factors can be quite difficult. I recommend implementing an algorithm to help you, such as Pollard's rho algorithm (although there are others that'll work, like trivial division).






    share|improve this answer











    $endgroup$












    • $begingroup$
      Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
      $endgroup$
      – Ken
      Mar 27 at 6:02











    • $begingroup$
      @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
      $endgroup$
      – TryingToPassCollege
      Mar 27 at 13:47










    • $begingroup$
      Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
      $endgroup$
      – poncho
      Mar 27 at 16:03














    5












    5








    5





    $begingroup$

    In general, proving that $g$ is a primitive root (often called a generator) of a cyclic group is fairly simple. Note this holds true for non prime modulo as well



    Step 1:



    Verify that $0leqslant g lt p$ and $(g,p)=1$



    In other words, verify that $g$ is less than p but greater than or equal to 0, and that $g$ and $p$ are coprime.



    Where $g$ is the element of the group in question and p is the modulus being used (or: $mathbbZ_p$).



    Step 2:



    Calculate $phi(p)$ where $phi$ is the Totient Function. If it happens that $p$ is prime, $phi(p)=p-1$



    Then break $phi(p)$ into it's prime factors such that $phi(p)=prodlimits_iq_i^r_i$ Where each $q_i$ is a prime factor and $r_i$ is the power that prime factor is raised to.



    (This notation simply implies that $phi(p)$ is to be broken down into it's prime factors $q_i$ such that $phi(p)=q_1^r_1times q_2^r_2times ...$)



    Verify that $g^phi(p)/q_inotequiv 1 (mod p)$ $forall q_i$



    Ignore the power $r_i$ for this calculation.



    Assuming these conditions are met, $g$ is a generator of $mathbbZ_p$.




    Example:



    Let $p=101$, $g=2$.



    Step 1:



    $0leqslant 2 lt 101$ $checkmark$



    and



    $(2,101) = 1$ $checkmark $



    Which can be checked using the Extended Euclidean Algorithm if $p$ is not prime (however, 101 is prime, so 2 is most definitely coprime to it).



    Step 2



    Calculate $phi(p)=p-1=phi(101)=101-1=100$ (Assuming $p$ is prime).



    Now that we know $phi(101)=100$, we can break it down into it's prime factors. Check that:



    $100=2^2times5^2$



    This means that our $q_1=2, q_2=5$. Remember that we ignore the powers $r_i$ of each of the prime factors for our computations.



    Finally, we check:



    $2^phi(101)/q_1=2^(101-1)/2=2^50equiv100notequiv1(mod 101)checkmark$
    $2^phi(101)/q_2=2^(101-1)/5=2^20equiv95notequiv1(mod 101)checkmark$



    $therefore g$ is a generator $mod 101$.



    (Read: therefore $g$ is a generator $mod 101$.)



    Note that this process is to be done $forall q_i$, in our case there were only two.



    (Read: note that this process is to be done for all $q_i$...)




    In your example, and in practical examples, $p$ is very large. First, confirming that $p$ is prime can be difficult. Second, factorizing $phi(p)$ into it's prme factors can be quite difficult. I recommend implementing an algorithm to help you, such as Pollard's rho algorithm (although there are others that'll work, like trivial division).






    share|improve this answer











    $endgroup$



    In general, proving that $g$ is a primitive root (often called a generator) of a cyclic group is fairly simple. Note this holds true for non prime modulo as well



    Step 1:



    Verify that $0leqslant g lt p$ and $(g,p)=1$



    In other words, verify that $g$ is less than p but greater than or equal to 0, and that $g$ and $p$ are coprime.



    Where $g$ is the element of the group in question and p is the modulus being used (or: $mathbbZ_p$).



    Step 2:



    Calculate $phi(p)$ where $phi$ is the Totient Function. If it happens that $p$ is prime, $phi(p)=p-1$



    Then break $phi(p)$ into it's prime factors such that $phi(p)=prodlimits_iq_i^r_i$ Where each $q_i$ is a prime factor and $r_i$ is the power that prime factor is raised to.



    (This notation simply implies that $phi(p)$ is to be broken down into it's prime factors $q_i$ such that $phi(p)=q_1^r_1times q_2^r_2times ...$)



    Verify that $g^phi(p)/q_inotequiv 1 (mod p)$ $forall q_i$



    Ignore the power $r_i$ for this calculation.



    Assuming these conditions are met, $g$ is a generator of $mathbbZ_p$.




    Example:



    Let $p=101$, $g=2$.



    Step 1:



    $0leqslant 2 lt 101$ $checkmark$



    and



    $(2,101) = 1$ $checkmark $



    Which can be checked using the Extended Euclidean Algorithm if $p$ is not prime (however, 101 is prime, so 2 is most definitely coprime to it).



    Step 2



    Calculate $phi(p)=p-1=phi(101)=101-1=100$ (Assuming $p$ is prime).



    Now that we know $phi(101)=100$, we can break it down into it's prime factors. Check that:



    $100=2^2times5^2$



    This means that our $q_1=2, q_2=5$. Remember that we ignore the powers $r_i$ of each of the prime factors for our computations.



    Finally, we check:



    $2^phi(101)/q_1=2^(101-1)/2=2^50equiv100notequiv1(mod 101)checkmark$
    $2^phi(101)/q_2=2^(101-1)/5=2^20equiv95notequiv1(mod 101)checkmark$



    $therefore g$ is a generator $mod 101$.



    (Read: therefore $g$ is a generator $mod 101$.)



    Note that this process is to be done $forall q_i$, in our case there were only two.



    (Read: note that this process is to be done for all $q_i$...)




    In your example, and in practical examples, $p$ is very large. First, confirming that $p$ is prime can be difficult. Second, factorizing $phi(p)$ into it's prme factors can be quite difficult. I recommend implementing an algorithm to help you, such as Pollard's rho algorithm (although there are others that'll work, like trivial division).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 27 at 13:50

























    answered Mar 26 at 23:48









    TryingToPassCollegeTryingToPassCollege

    613




    613











    • $begingroup$
      Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
      $endgroup$
      – Ken
      Mar 27 at 6:02











    • $begingroup$
      @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
      $endgroup$
      – TryingToPassCollege
      Mar 27 at 13:47










    • $begingroup$
      Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
      $endgroup$
      – poncho
      Mar 27 at 16:03

















    • $begingroup$
      Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
      $endgroup$
      – Ken
      Mar 27 at 6:02











    • $begingroup$
      @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
      $endgroup$
      – TryingToPassCollege
      Mar 27 at 13:47










    • $begingroup$
      Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
      $endgroup$
      – poncho
      Mar 27 at 16:03
















    $begingroup$
    Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
    $endgroup$
    – Ken
    Mar 27 at 6:02





    $begingroup$
    Hi @TryingToPassCollege, thank you so much. However, could you give an example? For learning purpose, for example, p = 2685735182104907 and g = 2.. I understand from Step 1 that from the looks of my p and g, it is definitely between 0 and p, and they are definitely coprime because I made a primality check on Java, and p is a prime. As such, g = 2, is a coprime as well. From step 2 onwards, I'm a little confused because tbh I don't understand most of the symbols. I feel like I'm lacking a lot of mathematics experience.. So sorry for all the trouble, as I don't have anyone else to turn to.
    $endgroup$
    – Ken
    Mar 27 at 6:02













    $begingroup$
    @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
    $endgroup$
    – TryingToPassCollege
    Mar 27 at 13:47




    $begingroup$
    @Ken I have added an example, a few read as descriptions to explain the symbols, and a small summary about applying this method if $p$ is large. Hope this helps.
    $endgroup$
    – TryingToPassCollege
    Mar 27 at 13:47












    $begingroup$
    Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
    $endgroup$
    – poncho
    Mar 27 at 16:03





    $begingroup$
    Note that non-prime modulii (specially, ones with two distinct odd prime factors) do not have generators; that is, there is no element $g$ where $g^x bmod n$ is all members of $mathbbZ_n^*$
    $endgroup$
    – poncho
    Mar 27 at 16:03












    1












    $begingroup$

    $p = 2685735182215187$ is prime, and $p - 1 = 2q$ where $q = 1342867591107593$ is prime, so the only possible orders of $g$ are $1, 2, q, 2q$, corresponding respectively to




    • $g equiv 1 pmod p$,


    • $g equiv -1 pmod p$,


    • $g$ is a nontrivial quadratic residue modulo $p$, i.e. there is some $h notin 0,pm1$ such that $g equiv h^2 pmod p$, and


    • $g$ is a nontrivial quadratic nonresidue modulo $p$, which in this case generates the whole group.

    If $g$ is neither $1$ nor $-1$, it suffices to compute the Legendre symbol of $g$, $$(g|p) := g^(p - 1)/2 bmod p = g^q bmod p,$$ which is 1 if $g$ is a quadratic residue and 0 or -1 if it is not. Obviously you can compute $g^q bmod p$ directly, as in poncho's answer which applies more generally, but for many values of $g$, there are special cases which you can test much more easily by the quadratic reciprocity theorem, that, for distinct odd primes $a$ and $b$, $(a|b) = -(b|a)$ if $a equiv b equiv 3 pmod 4$, whereas $(a|b) = (b|a)$ if either $a equiv 1 pmod 4$ or $b equiv 1 pmod 4$.




    • $3 equiv p equiv 3 pmod 4$, so $(3|p) = -(p|3) = -p^(3 - 1)/2 bmod 3 = -p^1 bmod 3 = 1$, so 3 is a quadratic residue and thus is not a generator of the whole group.


    • $5 equiv 1 pmod 4$, so $(5|p) = (p|5) = p^(5 - 1)/2 bmod 5 = p^2 bmod 5 = 4 bmod 5 = -1$, so 5 is a quadratic nonresidue and thus is a generator of the whole group.

    • The second supplement to the quadratic reciprocity theorem is that $g = 2$ is a quadratic residue modulo $p$ if and only if $p equiv pm 1 pmod 8$. In this case, $p equiv 3 pmod 8$, so 2 is a quadratic nonresidue and thus is a generator of the whole group.





    share|improve this answer











    $endgroup$

















      1












      $begingroup$

      $p = 2685735182215187$ is prime, and $p - 1 = 2q$ where $q = 1342867591107593$ is prime, so the only possible orders of $g$ are $1, 2, q, 2q$, corresponding respectively to




      • $g equiv 1 pmod p$,


      • $g equiv -1 pmod p$,


      • $g$ is a nontrivial quadratic residue modulo $p$, i.e. there is some $h notin 0,pm1$ such that $g equiv h^2 pmod p$, and


      • $g$ is a nontrivial quadratic nonresidue modulo $p$, which in this case generates the whole group.

      If $g$ is neither $1$ nor $-1$, it suffices to compute the Legendre symbol of $g$, $$(g|p) := g^(p - 1)/2 bmod p = g^q bmod p,$$ which is 1 if $g$ is a quadratic residue and 0 or -1 if it is not. Obviously you can compute $g^q bmod p$ directly, as in poncho's answer which applies more generally, but for many values of $g$, there are special cases which you can test much more easily by the quadratic reciprocity theorem, that, for distinct odd primes $a$ and $b$, $(a|b) = -(b|a)$ if $a equiv b equiv 3 pmod 4$, whereas $(a|b) = (b|a)$ if either $a equiv 1 pmod 4$ or $b equiv 1 pmod 4$.




      • $3 equiv p equiv 3 pmod 4$, so $(3|p) = -(p|3) = -p^(3 - 1)/2 bmod 3 = -p^1 bmod 3 = 1$, so 3 is a quadratic residue and thus is not a generator of the whole group.


      • $5 equiv 1 pmod 4$, so $(5|p) = (p|5) = p^(5 - 1)/2 bmod 5 = p^2 bmod 5 = 4 bmod 5 = -1$, so 5 is a quadratic nonresidue and thus is a generator of the whole group.

      • The second supplement to the quadratic reciprocity theorem is that $g = 2$ is a quadratic residue modulo $p$ if and only if $p equiv pm 1 pmod 8$. In this case, $p equiv 3 pmod 8$, so 2 is a quadratic nonresidue and thus is a generator of the whole group.





      share|improve this answer











      $endgroup$















        1












        1








        1





        $begingroup$

        $p = 2685735182215187$ is prime, and $p - 1 = 2q$ where $q = 1342867591107593$ is prime, so the only possible orders of $g$ are $1, 2, q, 2q$, corresponding respectively to




        • $g equiv 1 pmod p$,


        • $g equiv -1 pmod p$,


        • $g$ is a nontrivial quadratic residue modulo $p$, i.e. there is some $h notin 0,pm1$ such that $g equiv h^2 pmod p$, and


        • $g$ is a nontrivial quadratic nonresidue modulo $p$, which in this case generates the whole group.

        If $g$ is neither $1$ nor $-1$, it suffices to compute the Legendre symbol of $g$, $$(g|p) := g^(p - 1)/2 bmod p = g^q bmod p,$$ which is 1 if $g$ is a quadratic residue and 0 or -1 if it is not. Obviously you can compute $g^q bmod p$ directly, as in poncho's answer which applies more generally, but for many values of $g$, there are special cases which you can test much more easily by the quadratic reciprocity theorem, that, for distinct odd primes $a$ and $b$, $(a|b) = -(b|a)$ if $a equiv b equiv 3 pmod 4$, whereas $(a|b) = (b|a)$ if either $a equiv 1 pmod 4$ or $b equiv 1 pmod 4$.




        • $3 equiv p equiv 3 pmod 4$, so $(3|p) = -(p|3) = -p^(3 - 1)/2 bmod 3 = -p^1 bmod 3 = 1$, so 3 is a quadratic residue and thus is not a generator of the whole group.


        • $5 equiv 1 pmod 4$, so $(5|p) = (p|5) = p^(5 - 1)/2 bmod 5 = p^2 bmod 5 = 4 bmod 5 = -1$, so 5 is a quadratic nonresidue and thus is a generator of the whole group.

        • The second supplement to the quadratic reciprocity theorem is that $g = 2$ is a quadratic residue modulo $p$ if and only if $p equiv pm 1 pmod 8$. In this case, $p equiv 3 pmod 8$, so 2 is a quadratic nonresidue and thus is a generator of the whole group.





        share|improve this answer











        $endgroup$



        $p = 2685735182215187$ is prime, and $p - 1 = 2q$ where $q = 1342867591107593$ is prime, so the only possible orders of $g$ are $1, 2, q, 2q$, corresponding respectively to




        • $g equiv 1 pmod p$,


        • $g equiv -1 pmod p$,


        • $g$ is a nontrivial quadratic residue modulo $p$, i.e. there is some $h notin 0,pm1$ such that $g equiv h^2 pmod p$, and


        • $g$ is a nontrivial quadratic nonresidue modulo $p$, which in this case generates the whole group.

        If $g$ is neither $1$ nor $-1$, it suffices to compute the Legendre symbol of $g$, $$(g|p) := g^(p - 1)/2 bmod p = g^q bmod p,$$ which is 1 if $g$ is a quadratic residue and 0 or -1 if it is not. Obviously you can compute $g^q bmod p$ directly, as in poncho's answer which applies more generally, but for many values of $g$, there are special cases which you can test much more easily by the quadratic reciprocity theorem, that, for distinct odd primes $a$ and $b$, $(a|b) = -(b|a)$ if $a equiv b equiv 3 pmod 4$, whereas $(a|b) = (b|a)$ if either $a equiv 1 pmod 4$ or $b equiv 1 pmod 4$.




        • $3 equiv p equiv 3 pmod 4$, so $(3|p) = -(p|3) = -p^(3 - 1)/2 bmod 3 = -p^1 bmod 3 = 1$, so 3 is a quadratic residue and thus is not a generator of the whole group.


        • $5 equiv 1 pmod 4$, so $(5|p) = (p|5) = p^(5 - 1)/2 bmod 5 = p^2 bmod 5 = 4 bmod 5 = -1$, so 5 is a quadratic nonresidue and thus is a generator of the whole group.

        • The second supplement to the quadratic reciprocity theorem is that $g = 2$ is a quadratic residue modulo $p$ if and only if $p equiv pm 1 pmod 8$. In this case, $p equiv 3 pmod 8$, so 2 is a quadratic nonresidue and thus is a generator of the whole group.






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 18:08

























        answered Mar 27 at 17:59









        Squeamish OssifrageSqueamish Ossifrage

        23.2k133106




        23.2k133106



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Cryptography Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcrypto.stackexchange.com%2fquestions%2f68317%2fhow-to-verify-if-g-is-a-generator-for-p%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

            Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029