Implementing-cryptography-using-python
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 4 ■ Cryptographic Math and Frequency Analysis 109
Ideally, you now have a general idea of groups and subgroups. Enter “cosets”;
these are objects in abstract algebra that help you find subgroups using Lagrange’s
theorem. The theorem uses a simple rule that dramatically narrows down the
possible list of subgroups.
Recall that the notation for group H is a subgroup of group G: H ≤ G. Every
group has at least two subgroups. These include G itself and the trivial group =
{e}. The trivial group consists of only the identity element. The idea of Lagrange’s
theorem is to find if a group has more than these two subgroups. The theorem
states: if H ≤ G, then the order of H divides the order of G.
Recall that the order of a group G is the number of elements in the group
and it is denoted using the absolute value symbol |G|. This notation allows
you to write Lagrange’s theorem by stating: H ≤ G ➜ |H| divides |G|. What
the theorem is stating is that the subgroup H cannot be just any size and that
there are strong restrictions on the subsets of G. Here is a simplified example:
Let G be a group with |G| = 323 = 17 × 19
Divisors of 323: 1, 17, 19, 323
The results of the theorem present the possible orders of the subgroups include
1, 17, 19, and 323.
Every group has at least two subgroups: G (itself) and {e} (trivial group):
|G| = 323
|{e}| = 1
This means that if G has any other subgroups, their orders are 17 or 19. It is essential
to understand that the theorem is not stating that there are indeed subgroups of
order 17 and 19. In this case, it does, but there are many cases where it will not.
The proof of this is not that difficult. Mostly, a subgroup is closed under the
operation in question, so if you have some element that is not in the subgroup,
you can multiply or add it to the elements in the subgroup and get another set
not equal to the subgroup that has the same size. Repeat the process, and you’ll
chunk all the elements in G into “cosets” of H.
Modular Inverses
You’ll now turn your focus to modular inverses. For an integer a and a modulus
m you want to find a number n; the notation looks like the following: a −1 such
that n ° a ≡ 1 (mod m).
That is, it is the multiplicative inverse in the ring of integers modulo m. The
multiplicative inverse of a modulo m exists if and only if a and m are coprime
(i.e., if gcd(a, m) = 1).
For every number a and a prime p that a p − 1 ≡ 1 (mod p). If you need to compute
the inverse of a modulo p since a * a p − 2 = a p − 1 ≡ 1, when the modulus is
prime, you can compute a p − 2 (mod p).