The group of units-Primitive Roots-Discrete logarithm

The group Un ( Group of units)

It is noted that the set all numbers relatively prime to n ( gcd(a,n)=1 ) (units Un )forms a group in Zn under multiplication.

We say that a group G is abelian if its elements commute, that is gh=hg for all g,hG.The group Un is an abelian group under multiplication (modn).

If G is a finite group with an identity element e, the order of an element gG is the least integer k>0 such that gk=e, then the integers l such that gl=e are the multiples of k.

Example:

In U5 the element 2 have order 4.ie; 212,224,233,241(mod5), so k=4 is the least positive exponent such that 2k=1( the identity element) in U5.Similarly the element 1 has order 1, while the elements 3 and 4 have orders 4 and 2 respectively.

In U8 the elements 1,3,5,7 have orders 1,2,2,2 respectively.

Our aim is to describe the structure of the group Un for all n.To do this, it is not sufficient simply to know its order ϕ(n).For example since ϕ(5)=4=ϕ(8), the groups U5 and U8 bot have order 4.However these two groups are not isomorphic, since U5 has elements order 4 ,namely 2 and 3, where as U8 has none.In group theoretic terminology and notation, U5 is a cyclic group of order 4.(U5C4), generated by 2 or 3, where as U8 is a Klein Four Group (U8V4=C2×C2)

Primitive Root and  cyclic group : Definition

If Un is cyclic then any generator g for Un is called a primitive root (modn). This means that g has order equal to the order ϕ(n) of Un, so that the powers of g yield all the elements of Un.For instance, 2 and 3 are primitive roots (mod5).But there are no primitive roots (mod8), since U8 is not cyclic.

Finding primitive roots in Un (if they exist) is a non-trivial problem. and there is no simple solution. One obvious but tedious method is to try each of the ϕ(n) units aUn in turn each time computing the powers ai(modn) to find the order of a in Un;if we find an element a of order ϕ(n) then we know that this must be primitive root.

The following lemma helps in finding the primitive root efficiently

An element aUn is a  primitive root if and only if  aϕ(n)/q1 in Un  for each prime q dividing ϕ(n).

Example: Let n=11,ϕ(11)=10, So the prime factors of 10 are 2 and 5.Lets see whether a=2 is a primitive root.

25=3210(mod11)
22=44(mod11)
So both are 1, and hence we can conclude that 2 is a primitive root.We can verify this
21=2,22=4,23=8,24=5,25=10,26=9,27=7,28=3,29=6,210=1
Thus 2 has order 10 and its power gives all the elements of U11
If we apply lemma with a=3, we can find that 35=343=1(mod11). So 3 is not a primitive root in (mod11); its powers are 3,9,5,4,and 1

Example: Lets find a primitive root (mod17).We have ϕ(17)=16, which has only q=2 as a prime factor. The lemma implies that an element aU17 is primitive root if and only if a81 in U17.Trying a=2 first , we have 28=2561(mod17), so 2 is not a primitive root.How ever 3816(mod17), so 3 is a primitive root.

Example: Lets take another example where n is composite say 9.The group has ϕ(9)=6 elements.2 and 3 are the factors of ϕ(6).Thus an element aU9 is a primitive root if and only if a2,a31 in U9.Since 22,231(mod9) , we see that 2 is a primitive root.

Note: If Un has a primitive root then it has ϕ(ϕ(n)) of them.If p is prime then the group Up is cyclic.
If p is prime then Up has ϕ(d) elements of order d for each d dividing p1.

Example: The table below shows the powers of integers modulo 19.The primitive roots are 2,3,10,13,14,15.
It has ϕ(ϕ(19))=ϕ(18)=6 primitive roots.
The factors of 18 are 1,2,3,6,9,18
ϕ(1)=1- There is 1 element of order 1 which is 1
ϕ(2)=1- There is 1 element of order 2 which is 18
ϕ(3)=2- There are 2 elements of order 3 which are 7 and 11
ϕ(6)=2- There are 2 elements of order 6 which are 8 and 12
ϕ(9)=6- There are 6 elements of order 9 which are 4,5,6,9,16,17
ϕ(18)=6- There are 6 elements of order 18 which are 2,3,10,13,14,15 ( primitive roots)


Note: 
If p is an odd prime then Upe is cyclic for all e1.
If g is a primitive root (modp), where p is an odd prime, then g is usually a primitive root (modp2), in which case g is always a primitive root (modpe) for all e.For instance g=2 is a primitive root in U5 and also a primitive root in U52 and hence for all e.

The group U2e is cyclic only for e=1 or e=2.

Python code
Finding order of an element
from sympy.ntheory import n_order 
print(n_order(2, 19))
18
print(n_order(6, 19))
9
print(n_order(7, 19))
3
Checking primitive roots
from sympy.ntheory import is_primitive_root
print(is_primitive_root(2,19))
True
print(is_primitive_root(6,19))
False
Return Smallest Primitive Root
from sympy.ntheory.residue_ntheory import primitive_root
primitive_root(19)
2


Existence of Primitive Roots

How can we determine all integers  n for which there exist primitive root (modn)

Theorem: The group Un is cyclic if and only if n=1,2,4,pe,2pe, where p is an odd prime.

This can be verified for various values of n,

Lemma: if n=r.s, where  r and s are co prime and are both greater than 2, then Un is not cyclic.

Examples:
U8 is not cyclic because 8  is not of the form 1,2,4,pe,2pe, where p is an odd prime.
U15 is not cyclic because 15=3×5 and gcd(3,5)=1

Application of Primitive Roots

Discrete Logarithm Problem
With ordinary positive real numbers, the logarithm function is the inverse of exponentiation. An analogous function exists for modular arithmetic. Let us briefly review the properties of ordinary logarithms.The logarithm of a number is defined to be the power to which some positive base (except 1) must be raised in order to equal the number.That is, for base x and for a value y,
y=xlogx(y)

Consider a primitive root a for some prime number p(the argument can be developed for nonprimes as well). Then we know that the powers of a from 1 through (p1) produce each integer from 1 through (p1) exactly once.We also know that any integer b satisfies
br(modp)for somerwhere,0r(p1)

by the definition of modular arithmetic. It follows that for any integer b and a primitive root a of prime number p , we can find a unique exponent i such that

bai(modp)where,0i(p1)

This exponent i is referred to as the discrete logarithm of the number b for the base a(modp).We denote this value as dloga,p(b)

Note the following:
dloga,p(1)=0 because a0(modp)=1(modp)=1
dloga,p(a)=1  because a1(modp)=a


Note: Keep in mind that unique discrete logarithms (modm) to some base exist only if a is a primitive root of m.

Consider U19. The primitive root and discrete logarithm are shown in table below.


Calculation of Discrete Logarithms
Consider the equation
y=gx(modp)

Given g,x and p, it is a straightforward matter to calculate y. At the worst, we must perform x repeated multiplications, and algorithms exist for achieving greater efficiency.

However, given y,g, and p, it is, in general, very difficult to calculate x(take the discrete logarithm). The difficulty seems to be on the same order of magnitude as that of factoring primes required for RSA. There is no asymptotically fastest known algorithm for taking discrete logarithms modulo a prime number.

Python Code
from sympy.ntheory import discrete_log
print(discrete_log(19, 8, 2))
3
print(discrete_log(19, 10,15))
13



Solving Congruence
Consider solving the congruence(find x)  given m,c and n
xmc(modn)

Example:
Consider the congruence x413(mod17).
First note that any solution x must be a unit (mod17). This group is cyclic, so both x and 13 can be expressed as a power of a primitive root g(mod17).3 is a primitive root of this group U17 and 3413(mod17).So we can write the congruence 34i34(mod17).It is noted that 34i34(mod17) only if  4i=4(mod16) or equivalently i1(mod4)

The relevant values of i (between 0 and 15) are therefore 1,5,9,13. So the solutions of the original congruence are x3,35,39and313 

Note:if there exist a primitive root g(modn), writing x=gi and c=gb, we convert the original non linear congruence xmc(modn) into linear congruence mib(modϕ(n))

Application- Diffie-Hellman Key Exchange
The Diffie-Hellman key exchange algorithm is a method for securely exchanging cryptographic keys over a public channel. This method allows two parties to jointly establish a shared secret key, which can then be used for secure communications. The algorithm is based on the difficulty of solving the discrete logarithm problem in finite fields.

Steps of the Diffie-Hellman Key Exchange Algorithm:
    1. Agree on Parameters:

      • Both parties agree on a large prime number and a base , which is known as a generator of a cyclic group. These parameters can be public and are not considered secret.
    2. Generate Private Keys:

      • Each party generates a private key randomly. Let's denote the private key of Alice as
        and the private key of Bob as . These private keys remain secret and are not ransmitted over the network.
    3. Compute Public Keys:

      • Each party computes their public key by raising the base to the power of their private key and taking the modulus .
        • Alice computes her public key as follows: =mod.
        • Bob computes his public key as follows: =mod.
      • Alice and Bob then exchange their public keys over the public channel.
    4. Compute the Shared Secret:

      • Each party computes the shared secret key using the public key received from the other party and their own private key. This computation will result in the same shared secret for both parties.
        • Alice computes the shared secret using Bob's public key: =mod.
        • Bob computes the shared secret using Alice's public key: =mod.

    Due to the properties of exponentiation in modular arithmetic, both computations for the shared secret will result in the same value:

    =mod=()mod=mod =mod=()mod=mod

    Example:

    Let's use a toy example to illustrate this:

    • Let the prime =23 and the base =5.
    • Alice selects a private key =6.
    • Bob selects a private key =15.
    1. Compute Public Keys:

      • Alice computes her public key: =56mod23=8.
      • Bob computes his public key: =515mod23=2.
    2. Exchange Public Keys:

      • Alice sends =8 to Bob, and Bob sends =2 to Alice.
    3. Compute the Shared Secret:

      • Alice computes the shared secret: =mod=26mod23=9.
      • Bob computes the shared secret: =mod=815mod23=9.

    Both Alice and Bob now share the secret key
    =9

    This example simplifies the actual calculations to make it easy to follow. In real-world applications, the numbers involved are typically very large to ensure security against attacks, such as trying all possible keys (brute-force attack).

Comments

Popular posts from this blog

Number Theory CST 292 KTU IV Semester Honors Course Notes Dr Binu V P 9847390760

Sum of Squares

Well Ordering Principle