Element order and Lagrange's theorem
Z*p is a group under multiplication modulo mod p; it has p-1 elements. The order of the element h is the smallest positive number k such that h^k ≡ 1 (mod p).
Lagrange's theorem provides a very strong constraint: the order of any element divides the group order, that is, p-1. Therefore, it is not necessary to check all numbers — it is sufficient to check only the divisors of p-1.
In Diffie-Hellman, this is a security issue: if the generator has a small order, very few options remain for the shared key, and the attacker will brute-force it.
Below, p, its factorization p-1 and the element h are given. Find the order of h.
p = 4085559242614864307
p - 1 = 2 * 1030739 * 1082189 * 1831343
h = 1797234111894391568
Answer: only the number — in decimal format, without spaces and extra characters (for example 1234).