Hubbry Logo
Modular multiplicative inverseModular multiplicative inverseMain
Open search
Modular multiplicative inverse
Community hub
Modular multiplicative inverse
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Modular multiplicative inverse
Modular multiplicative inverse
from Wikipedia

In mathematics, particularly in the area of arithmetic, a modular multiplicative inverse of an integer a is an integer x such that the product ax is congruent to 1 with respect to the modulus m.[1] In the standard notation of modular arithmetic this congruence is written as

which is the shorthand way of writing the statement that m divides (evenly) the quantity ax − 1, or, put another way, the remainder after dividing ax by the integer m is 1. If a does have an inverse modulo m, then there is an infinite number of solutions of this congruence, which form a congruence class with respect to this modulus. Furthermore, any integer that is congruent to a (i.e., in a's congruence class) has any element of x's congruence class as a modular multiplicative inverse. Using the notation of to indicate the congruence class containing w, this can be expressed by saying that the modulo multiplicative inverse of the congruence class is the congruence class such that:

where the symbol denotes the multiplication of equivalence classes modulo m.[2] Written in this way, the analogy with the usual concept of a multiplicative inverse in the set of rational or real numbers is clearly represented, replacing the numbers by congruence classes and altering the binary operation appropriately.

As with the analogous operation on the real numbers, a fundamental use of this operation is in solving, when possible, linear congruences of the form

Finding modular multiplicative inverses also has practical applications in the field of cryptography, e.g. public-key cryptography and the RSA algorithm.[3][4][5] A benefit for the computer implementation of these applications is that there exists a very fast algorithm (the extended Euclidean algorithm) that can be used for the calculation of modular multiplicative inverses.

Modular arithmetic

[edit]

For a given positive integer m, two integers, a and b, are said to be congruent modulo m if m divides their difference. This binary relation is denoted by,

This is an equivalence relation on the set of integers, , and the equivalence classes are called congruence classes modulo m or residue classes modulo m. Let denote the congruence class containing the integer a,[6] then

A linear congruence is a modular congruence of the form

Unlike linear equations over the reals, linear congruences may have zero, one or several solutions. If x is a solution of a linear congruence then every element in is also a solution, so, when speaking of the number of solutions of a linear congruence we are referring to the number of different congruence classes that contain solutions.

If d is the greatest common divisor of a and m then the linear congruence axb (mod m) has solutions if and only if d divides b. If d divides b, then there are exactly d solutions.[7]

A modular multiplicative inverse of an integer a with respect to the modulus m is a solution of the linear congruence

The previous result says that a solution exists if and only if gcd(a, m) = 1, that is, a and m must be relatively prime (i.e. coprime). Furthermore, when this condition holds, there is exactly one solution, i.e., when it exists, a modular multiplicative inverse is unique:[8] If b and b' are both modular multiplicative inverses of a respect to the modulus m, then

therefore

If a ≡ 0 (mod m), then gcd(a, m) = m, and a won't even have a modular multiplicative inverse. Therefore, b ≡ b' (mod m).

When ax ≡ 1 (mod m) has a solution it is often denoted in this way −

but this can be considered an abuse of notation since it could be misinterpreted as the reciprocal of (which, contrary to the modular multiplicative inverse, is not an integer except when a is 1 or −1). The notation would be proper if a is interpreted as a token standing for the congruence class , as the multiplicative inverse of a congruence class is a congruence class with the multiplication defined in the next section.

Integers modulo m

[edit]

The congruence relation, modulo m, partitions the set of integers into m congruence classes. Operations of addition and multiplication can be defined on these m objects in the following way: To either add or multiply two congruence classes, first pick a representative (in any way) from each class, then perform the usual operation for integers on the two representatives and finally take the congruence class that the result of the integer operation lies in as the result of the operation on the congruence classes. In symbols, with and representing the operations on congruence classes, these definitions are

and

These operations are well-defined, meaning that the end result does not depend on the choices of representatives that were made to obtain the result.

The m congruence classes with these two defined operations form a ring, called the ring of integers modulo m. There are several notations used for these algebraic objects, most often or , but several elementary texts and application areas use a simplified notation when confusion with other algebraic objects is unlikely.

The congruence classes of the integers modulo m were traditionally known as residue classes modulo m, reflecting the fact that all the elements of a congruence class have the same remainder (i.e., "residue") upon being divided by m. Any set of m integers selected so that each comes from a different congruence class modulo m is called a complete system of residues modulo m.[9] The division algorithm shows that the set of integers, {0, 1, 2, ..., m − 1} form a complete system of residues modulo m, known as the least residue system modulo m. In working with arithmetic problems it is sometimes more convenient to work with a complete system of residues and use the language of congruences while at other times the point of view of the congruence classes of the ring is more useful.[10]

Multiplicative group of integers modulo m

[edit]

Not every element of a complete residue system modulo m has a modular multiplicative inverse, for instance, zero never does. After removing the elements of a complete residue system that are not relatively prime to m, what is left is called a reduced residue system, all of whose elements have modular multiplicative inverses. The number of elements in a reduced residue system is , where is the Euler totient function, i.e., the number of positive integers less than m that are relatively prime to m.

In a general ring with unity not every element has a multiplicative inverse and those that do are called units. As the product of two units is a unit, the units of a ring form a group, the group of units of the ring and often denoted by R× if R is the name of the ring. The group of units of the ring of integers modulo m is called the multiplicative group of integers modulo m, and it is isomorphic to a reduced residue system. In particular, it has order (size), .

In the case that m is a prime, say p, then and all the non-zero elements of have multiplicative inverses, thus is a finite field. In this case, the multiplicative group of integers modulo p form a cyclic group of order p − 1.

Example

[edit]

For any integer , it's always the case that is the modular multiplicative inverse of with respect to the modulus , since . Examples are , , and so on.

The following example uses the modulus 10: Two integers are congruent mod 10 if and only if their difference is divisible by 10, for instance

since 10 divides 32 − 2 = 30, and
since 10 divides 111 − 1 = 110.

Some of the ten congruence classes with respect to this modulus are:

and

The linear congruence 4x ≡ 5 (mod 10) has no solutions since the integers that are congruent to 5 (i.e., those in ) are all odd while 4x is always even. However, the linear congruence 4x ≡ 6 (mod 10) has two solutions, namely, x = 4 and x = 9. The gcd(4, 10) = 2 and 2 does not divide 5, but does divide 6.

Since gcd(3, 10) = 1, the linear congruence 3x ≡ 1 (mod 10) will have solutions, that is, modular multiplicative inverses of 3 modulo 10 will exist. In fact, 7 satisfies this congruence (i.e., 21 − 1 = 20). However, other integers also satisfy the congruence, for instance 17 and −3 (i.e., 3(17) − 1 = 50 and 3(−3) − 1 = −10). In particular, every integer in will satisfy the congruence since these integers have the form 7 + 10r for some integer r and

is divisible by 10. This congruence has only this one congruence class of solutions. The solution in this case could have been obtained by checking all possible cases, but systematic algorithms would be needed for larger moduli and these will be given in the next section.

The product of congruence classes and can be obtained by selecting an element of , say 25, and an element of , say −2, and observing that their product (25)(−2) = −50 is in the congruence class . Thus, . Addition is defined in a similar way. The ten congruence classes together with these operations of addition and multiplication of congruence classes form the ring of integers modulo 10, i.e., .

A complete residue system modulo 10 can be the set {10, −9, 2, 13, 24, −15, 26, 37, 8, 9} where each integer is in a different congruence class modulo 10. The unique least residue system modulo 10 is {0, 1, 2, ..., 9}. A reduced residue system modulo 10 could be {1, 3, 7, 9}. The product of any two congruence classes represented by these numbers is again one of these four congruence classes. This implies that these four congruence classes form a group, in this case the cyclic group of order four, having either 3 or 7 as a (multiplicative) generator. The represented congruence classes form the group of units of the ring . These congruence classes are precisely the ones which have modular multiplicative inverses.

Computation

[edit]

Extended Euclidean algorithm

[edit]

A modular multiplicative inverse of a modulo m can be found by using the extended Euclidean algorithm.

The Euclidean algorithm determines the greatest common divisor (gcd) of two integers, say a and m. If a has a multiplicative inverse modulo m, this gcd must be 1. The last of several equations produced by the algorithm may be solved for this gcd. Then, using a method called "back substitution", an expression connecting the original parameters and this gcd can be obtained. In other words, integers x and y can be found to satisfy Bézout's identity,

Rewritten, this is

that is,

so, a modular multiplicative inverse of a has been calculated. A more efficient version of the algorithm is the extended Euclidean algorithm, which, by using auxiliary equations, reduces two passes through the algorithm (back substitution can be thought of as passing through the algorithm in reverse) to just one.

In big O notation, this algorithm runs in time O(log2(m)), assuming |a| < m, and is considered to be very fast and generally more efficient than its alternative, exponentiation.

Using Euler's theorem

[edit]

As an alternative to the extended Euclidean algorithm, Euler's theorem may be used to compute modular inverses.[11]

According to Euler's theorem, if a is coprime to m, that is, gcd(a, m) = 1, then

where is Euler's totient function. This follows from the fact that a belongs to the multiplicative group × if and only if a is coprime to m. Therefore, a modular multiplicative inverse can be found directly:

In the special case where m is a prime, and a modular inverse is given by

This method is generally slower than the extended Euclidean algorithm, but is sometimes used when an implementation for modular exponentiation is already available. Some disadvantages of this method include:

  • The value must be known and the most efficient known computation requires m's factorization. Factorization is widely believed to be a computationally hard problem. However, calculating is straightforward when the prime factorization of m is known.
  • The relative cost of exponentiation. Though it can be implemented more efficiently using modular exponentiation, when large values of m are involved this is most efficiently computed with the Montgomery reduction method, that method, itself, requiring a modular inverse mod m, which is what was to be calculated in the first place. Without the Montgomery method, the standard binary exponentiation, which requires division mod m at every step, is a slow operation when m is large.

One notable advantage of this technique is that there are no conditional branches which depend on the value of a, and thus the value of a, which may be an important secret in public-key cryptography, can be protected from side-channel attacks. For this reason, the standard implementation of Curve25519 uses this technique to compute an inverse.

Multiple inverses

[edit]

It is possible to compute the inverse of multiple numbers ai, modulo a common m, with a single invocation of the Euclidean algorithm and three multiplications per additional input.[12] The basic idea is to form the product of all the ai, invert that, then multiply by aj for all ji to leave only the desired a−1
i
.

More specifically, the algorithm is (all arithmetic performed modulo m):

  1. Compute the prefix products for all in.
  2. Compute b−1
    n
    using any available algorithm.
  3. For i from n down to 2, compute
    • a−1
      i
      = b−1
      i
      bi−1
      and
    • b−1
      i−1
      = b−1
      i
      ai
      .
  4. Finally, a−1
    1
    = b−1
    1
    .

It is possible to perform the multiplications in a tree structure rather than linearly to exploit parallel computing.

Inverses modulo prime powers (including powers of 2)

[edit]

In the case where the modulus m is on the form for some prime number p and positive integer m, it is possible to compute modular multiplicative inverses efficiently by using the Newton-Raphson iteration, allowing the inverse to be computed with multiplications. It can be shown that if

(that is, x is a modular multiplicative inverse of a modulo ), then

which means that it is possible to perform a modulo calculation by first computing a modular multiplicative inverse of a modulo the prime number p or a small power thereof, then performing a series of Newton-Raphson iterations to compute the inverse modulo progressively larger prime powers for progressively larger values of n.[13][14]

A practical use of this method is to efficiently compute modular multiplicative inverses modulo powers of 2. For such a calculation, one could start with noting that all odd integers are their own modular multiplicative inverses modulo , as can be shown by inspection:

,
,
,
,

and then iteratively use Newton-Raphson iterations to compute the modular inverse modulo , , and so on.

For example, in the C programming language, where additions, subtractions and multiplications on the uint64_t data type are all done modulo , one could compute the modular multiplicative inverse of an odd integer a modulo using the following function that performs five Newton-Raphson iterations:

#include <stdint.h>
uint64_t modinv64( uint64_t a ) {
    uint64_t x = a;
    for( int i=0; i<5; i++ )  x *= 2 - a*x;
    return x;
}

Depending on application and platform, it may make sense to optimize this routine further — e.g. the first few iterations can be skipped by using a lookup table to provide an inverse modulo a larger power-of-2; also, on some systems, 32-bit multiplications may be faster than 64-bit multiplications, in which case some speedup can be obtained by only using 32-bit multiplications until an inverse modulo has been obtained and then switch to 64-bit multiplications only after that. Applying such optimizations, a C routine that computes a modular multiplicative inverse modulo becomes:

#include <stdint.h>
uint64_t modinv64( uint64_t a ) {
    static const uint8_t tbl[256] = {
        0,1,0,171,0,205,0,183,0,57,0,163,0,197,0,239,
        0,241,0,27,0,61,0,167,0,41,0,19,0,53,0,223,
        0,225,0,139,0,173,0,151,0,25,0,131,0,165,0,207,
        0,209,0,251,0,29,0,135,0,9,0,243,0,21,0,191,
        0,193,0,107,0,141,0,119,0,249,0,99,0,133,0,175,
        0,177,0,219,0,253,0,103,0,233,0,211,0,245,0,159,
        0,161,0,75,0,109,0,87,0,217,0,67,0,101,0,143,
        0,145,0,187,0,221,0,71,0,201,0,179,0,213,0,127,
        0,129,0,43,0,77,0,55,0,185,0,35,0,69,0,111,
        0,113,0,155,0,189,0,39,0,169,0,147,0,181,0,95,
        0,97,0,11,0,45,0,23,0,153,0,3,0,37,0,79,
        0,81,0,123,0,157,0,7,0,137,0,115,0,149,0,63,
        0,65,0,235,0,13,0,247,0,121,0,227,0,5,0,47,
        0,49,0,91,0,125,0,231,0,105,0,83,0,117,0,31,
        0,33,0,203,0,237,0,215,0,89,0,195,0,229,0,15,
        0,17,0,59,0,93,0,199,0,73,0,51,0,85,0,255 };
    uint32_t a32 = (uint32_t)a;
    uint32_t x = tbl[a & 0xFF];  // inverse modulo 2^8
    x *= 2 - a32*x;        // 32-bit multiplications
    x *= 2 - a32*x;        // 32-bit multiplications
    return x * (2 - a*x);  // 64-bit multiplications
}

Applications

[edit]

Finding a modular multiplicative inverse has many applications in algorithms that rely on the theory of modular arithmetic. For instance, in cryptography the use of modular arithmetic permits some operations to be carried out more quickly and with fewer storage requirements, while other operations become more difficult.[15] Both of these features can be used to advantage. In particular, in the RSA algorithm, encrypting and decrypting a message is done using a pair of numbers that are multiplicative inverses with respect to a carefully selected modulus. One of these numbers is made public and can be used in a rapid encryption procedure, while the other, used in the decryption procedure, is kept hidden. Determining the hidden number from the public number is considered to be computationally infeasible and this is what makes the system work to ensure privacy.[16]

As another example in a different context, consider the exact division problem in computer science where you have a list of odd word-sized numbers each divisible by k and you wish to divide them all by k. One solution is as follows:

  1. Use the extended Euclidean algorithm to compute k−1, the modular multiplicative inverse of k mod 2w, where w is the number of bits in a word. This inverse will exist since the numbers are odd and the modulus has no odd factors.
  2. For each number in the list, multiply it by k−1 and take the least significant word of the result.

On many machines, particularly those without hardware support for division, division is a slower operation than multiplication, so this approach can yield a considerable speedup. The first step is relatively slow but only needs to be done once.

Modular multiplicative inverses are used to obtain a solution of a system of linear congruences that is guaranteed by the Chinese Remainder Theorem.

For example, the system

X ≡ 4 (mod 5)
X ≡ 4 (mod 7)
X ≡ 6 (mod 11)

has common solutions since 5,7 and 11 are pairwise coprime. A solution is given by

X = t1 (7 × 11) × 4 + t2 (5 × 11) × 4 + t3 (5 × 7) × 6

where

t1 = 3 is the modular multiplicative inverse of 7 × 11 (mod 5),
t2 = 6 is the modular multiplicative inverse of 5 × 11 (mod 7) and
t3 = 6 is the modular multiplicative inverse of 5 × 7 (mod 11).

Thus,

X = 3 × (7 × 11) × 4 + 6 × (5 × 11) × 4 + 6 × (5 × 7) × 6 = 3504

and in its unique reduced form

X ≡ 3504 ≡ 39 (mod 385)

since 385 is the LCM of 5,7 and 11.

Also, the modular multiplicative inverse figures prominently in the definition of the Kloosterman sum.

See also

[edit]

Notes

[edit]

References

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
In modular arithmetic, the modular multiplicative inverse of an integer aa modulo an integer m>1m > 1 is an integer bb such that ab1(modm)a b \equiv 1 \pmod{m}, meaning mm divides ab1a b - 1 but not necessarily aa or bb. Such an inverse exists if and only if aa and mm are relatively prime, that is, their greatest common divisor satisfies gcd(a,m)=1\gcd(a, m) = 1. When it exists, the inverse is unique modulo mm, and it enables "division" in the ring of integers modulo mm by allowing multiplication by bb to undo multiplication by aa. The existence of modular multiplicative inverses is a cornerstone of elementary , directly tied to , which states that gcd(a,m)=1\gcd(a, m) = 1 there exist integers xx and yy such that ax+my=1a x + m y = 1; here, x(modm)x \pmod{m} is the inverse of aa. Computationally, the inverse is efficiently found using the , which not only computes gcd(a,m)\gcd(a, m) but also yields the coefficients from . For prime moduli pp, every nonzero aa modulo pp has an inverse, forming the Zp×\mathbb{Z}_p^\times, and provides a method to compute it as ap2(modp)a^{p-2} \pmod{p}. Modular inverses play a vital role in applications beyond , particularly in , where they are essential for constructing secure systems like the RSA algorithm. In RSA, the private decryption exponent dd is the modular multiplicative inverse of the public encryption exponent ee modulo ϕ(n)\phi(n), where nn is the product of two large primes and ϕ\phi is , allowing efficient decryption while keeping the factorization of nn secret. They also underpin and other protocols by facilitating and point decompression in finite fields.

Modular Arithmetic Basics

Congruences and Equivalence Classes

In modular arithmetic, two integers aa and bb are said to be congruent modulo nn, where nn is a positive integer, denoted ab(modn)a \equiv b \pmod{n}, if nn divides the difference aba - b. This relation is an on the set of integers, satisfying reflexivity (aa(modn)a \equiv a \pmod{n}), (if ab(modn)a \equiv b \pmod{n}, then ba(modn)b \equiv a \pmod{n}), and transitivity (if ab(modn)a \equiv b \pmod{n} and bc(modn)b \equiv c \pmod{n}, then ac(modn)a \equiv c \pmod{n}). The partitions the integers into equivalence classes, known as residue classes nn. The residue class of aa nn, denoted n_n, consists of all integers bb such that ba(modn)b \equiv a \pmod{n}, or equivalently, n={a+knkZ}_n = \{a + kn \mid k \in \mathbb{Z}\}. There are exactly nn distinct residue classes nn, typically represented by the integers 0,1,,n10, 1, \dots, n-1. Congruences support basic arithmetic operations: if ab(modn)a \equiv b \pmod{n} and cd(modn)c \equiv d \pmod{n}, then a+cb+d(modn)a + c \equiv b + d \pmod{n} and acbd(modn)a \cdot c \equiv b \cdot d \pmod{n}. These operations are well-defined on the set of residue classes, allowing arithmetic to be performed nn without altering equivalence. The set of residue classes nn, denoted Z/nZ\mathbb{Z}/n\mathbb{Z}, forms a under these addition and multiplication operations, with the 0(modn)0 \pmod{n} and multiplicative identity 1(modn)1 \pmod{n}.

Greatest Common Divisor in Modular Contexts

In modular arithmetic, the greatest common divisor (GCD) of two integers aa and nn, where n>0n > 0, plays a crucial role in determining the structure of solutions to equations within the ring of integers modulo nn. The Euclidean algorithm provides an efficient method to compute gcd(a,n)\gcd(a, n) by leveraging the division algorithm repeatedly. Specifically, the algorithm states that gcd(a,n)=gcd(n,amodn)\gcd(a, n) = \gcd(n, a \mod n), and it proceeds by replacing aa with nn and nn with the remainder amodna \mod n until the remainder is zero; the last non-zero remainder is the GCD. This process terminates because the remainders form a strictly decreasing sequence of non-negative integers. If the algorithm terminates with a GCD of 1, then aa and nn are coprime. For an illustrative example, consider computing gcd(15,28)\gcd(15, 28): 28=115+13,15=113+2,13=62+1,2=21+0.\begin{align*} 28 &= 1 \cdot 15 + 13, \\ 15 &= 1 \cdot 13 + 2, \\ 13 &= 6 \cdot 2 + 1, \\ 2 &= 2 \cdot 1 + 0. \end{align*} The last non-zero is 1, so gcd(15,28)=1\gcd(15, 28) = 1, indicating that 15 and 28 are coprime. Bézout's identity further connects the GCD to linear combinations: if d=gcd(a,n)d = \gcd(a, n), then there exist integers xx and yy such that ax+ny=da x + n y = d. Moreover, the set of all integer s of aa and nn consists precisely of the multiples of dd. A proof sketch relies on the Euclidean algorithm's steps, using back-substitution to express the GCD as such a combination. Starting from the base case where the is dd (with previous 0), substitute backwards through the division steps. For instance, in the example above for gcd(15,28)=1\gcd(15, 28) = 1: 1=1362,2=151131=136(15113)=713615,13=281151=7(28115)615=7281315.\begin{align*} 1 &= 13 - 6 \cdot 2, \\ 2 &= 15 - 1 \cdot 13 \quad \Rightarrow \quad 1 = 13 - 6 \cdot (15 - 1 \cdot 13) = 7 \cdot 13 - 6 \cdot 15, \\ 13 &= 28 - 1 \cdot 15 \quad \Rightarrow \quad 1 = 7 \cdot (28 - 1 \cdot 15) - 6 \cdot 15 = 7 \cdot 28 - 13 \cdot 15. \end{align*} Thus, x=13x = -13 and y=7y = 7 satisfy 15(13)+28(7)=115(-13) + 28(7) = 1. This back-substitution works generally because each is a linear combination of the originals, propagating the expression upwards. Two integers aa and nn are defined as coprime if gcd(a,n)=1\gcd(a, n) = 1. In the context of congruences, which equate integers differing by multiples of the modulus, coprimality has significant implications for solvability. Specifically, the linear congruence axb(modn)a x \equiv b \pmod{n} is solvable for xx gcd(a,n)\gcd(a, n) divides bb; when gcd(a,n)=1\gcd(a, n) = 1, the congruence is always solvable for any bb, with exactly one solution nn. This condition ensures that the coefficient aa generates all residue classes nn when coprime, facilitating unique solutions in modular equations.

Definition and Conditions

Formal Definition

In modular arithmetic, the modular multiplicative inverse of an integer aa modulo nn, where n>1n > 1 is a positive integer, is an integer xx satisfying the congruence ax1(modn)a x \equiv 1 \pmod{n}. This xx is commonly denoted as xa1(modn)x \equiv a^{-1} \pmod{n}. Algebraically, this concept corresponds to the in the ring Z/nZ\mathbb{Z}/n\mathbb{Z} of integers nn, where aa and its inverse xx are elements whose product is the multiplicative identity 11 in the ring. The relation is symmetric: if xx is the modular multiplicative inverse of aa nn, then aa is the modular multiplicative inverse of xx nn.

Existence Criteria

The existence of a modular multiplicative inverse for an aa n>1n > 1 is determined by a fundamental condition in : such an inverse exists gcd(a,n)=1\gcd(a, n) = 1. This criterion ensures that aa and nn are coprime, meaning they share no common prime factors other than 1. When this holds, there exists an xx such that ax1(modn)a x \equiv 1 \pmod{n}. To establish this theorem, consider the necessity first. Suppose an inverse xx exists, so ax1(modn)a x \equiv 1 \pmod{n}, which implies axnk=1a x - n k = 1 for some integer kk. Any common divisor of aa and nn must divide the left side axnka x - n k, hence it divides 1, forcing gcd(a,n)=1\gcd(a, n) = 1. For sufficiency, if gcd(a,n)=1\gcd(a, n) = 1, guarantees integers xx and yy such that ax+ny=1a x + n y = 1, or equivalently, ax1(modn)a x \equiv 1 \pmod{n}. Thus, xx serves as the inverse. If gcd(a,n)=d>1\gcd(a, n) = d > 1, no inverse exists. In this case, dd divides aa, so for any xx, ax0(modd)a x \equiv 0 \pmod{d}. However, since dd does not divide 1, ax≢1(modd)a x \not\equiv 1 \pmod{d}, and thus ax≢1(modn)a x \not\equiv 1 \pmod{n} because nn is a multiple of dd. This impossibility arises because the equation ax1(modn)a x \equiv 1 \pmod{n} would require consistency modulo every of nn, including dd. This existence criterion extends to the broader solvability of linear congruences. The equation axb(modn)a x \equiv b \pmod{n} has solutions gcd(a,n)\gcd(a, n) divides bb. When b=1b = 1, this reduces to the inverse case, but the condition allows for solutions even when gcd(a,n)>1\gcd(a, n) > 1, provided the gcd divides bb, with the number of distinct solutions nn then equaling the gcd value.

Properties and Uniqueness

Uniqueness of Inverses

When a modular multiplicative inverse exists for an aa modulo nn, it is unique modulo nn. Specifically, if ax1(modn)ax \equiv 1 \pmod{n} and ay1(modn)ay \equiv 1 \pmod{n}, then xy(modn)x \equiv y \pmod{n}. To prove this, subtract the congruences to obtain a(xy)0(modn)a(x - y) \equiv 0 \pmod{n}, meaning nn divides a(xy)a(x - y). Since the existence of the inverse requires gcd(a,n)=1\gcd(a, n) = 1, it follows that nn divides (xy)(x - y), so xy(modn)x \equiv y \pmod{n}. This uniqueness holds under the existence criterion that gcd(a,n)=1\gcd(a, n) = 1. The modular inverses modulo nn exhibit several basic properties. First, the set of integers coprime to nn (those possessing inverses) is closed under modulo nn: if gcd(a,n)=1\gcd(a, n) = 1 and gcd(b,n)=1\gcd(b, n) = 1, then gcd(abmodn,n)=1\gcd(ab \mod n, n) = 1. Second, the inverse of an inverse recovers the original element: if bb is the inverse of aa modulo nn, then the inverse of bb is aa modulo nn. This follows because ab1(modn)ab \equiv 1 \pmod{n} and, by commutativity of , ba1(modn)ba \equiv 1 \pmod{n}, so aa satisfies the defining congruence for the inverse of bb. Finally, the inverse of the a-a nn is the of the inverse of aa: if bb is the inverse of aa, then bmodn-b \mod n is the inverse of amodn-a \mod n, since (a)(b)ab1(modn)(-a)(-b) \equiv ab \equiv 1 \pmod{n}.

Connection to Units in Rings

In the ring Z/nZ\mathbb{Z}/n\mathbb{Z}, the units are the residue classes $$ where gcd(a,n)=1\gcd(a, n) = 1, as these are precisely the elements that admit multiplicative inverses under the ring's operation. These units form a multiplicative known as the group of units, denoted U(n)U(n) or (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times, consisting of all such invertible elements closed under modulo nn. The group U(n)U(n) is abelian, reflecting the commutative nature of multiplication in Z/nZ\mathbb{Z}/n\mathbb{Z}. Its order is given by ϕ(n)\phi(n), which counts the number of integers from 1 to n1n-1 coprime to nn. Within this group structure, the modular multiplicative inverse of an element U(n) \in U(n) coincides with its group inverse [a1][a^{-1}], satisfying \cdot [a^{-1}] = {{grok:render&&&type=render_inline_citation&&&citation_id=1&&&citation_type=wikipedia}} in Z/nZ\mathbb{Z}/n\mathbb{Z}. As a consequence of , this inverse is unique for each unit. A key structural property arises from the : when n=pqn = pq with gcd(p,q)=1\gcd(p, q) = 1, the ring Z/nZZ/pZ×Z/qZ\mathbb{Z}/n\mathbb{Z} \cong \mathbb{Z}/p\mathbb{Z} \times \mathbb{Z}/q\mathbb{Z} induces a U(n)U(p)×U(q)U(n) \cong U(p) \times U(q). This decomposition allows inverses modulo nn to be computed via separate inverses modulo pp and qq, combined using the theorem's reconstruction mechanism.

Computation Techniques

Extended Euclidean Algorithm

The extended Euclidean algorithm provides an efficient method to compute the modular multiplicative inverse of an integer aa modulo nn, assuming gcd(a,n)=1\gcd(a, n) = 1. This algorithm extends the standard for finding the by also determining integers xx and yy such that ax+ny=1a x + n y = 1, based on Bézout's identity. When gcd(a,n)=1\gcd(a, n) = 1, the value xmodnx \mod n serves as the modular inverse, since ax1(modn)a x \equiv 1 \pmod{n}. The algorithm proceeds in two phases. First, apply the to compute gcd(a,n)\gcd(a, n) through successive divisions: divide nn by aa to get q1q_1 and r1=nq1ar_1 = n - q_1 a, then aa by r1r_1 to get q2q_2 and r2=aq2r1r_2 = a - q_2 r_1, and continue until the remainder is 1 (since the gcd is 1). This generates a sequence of equations expressing each as a of aa and nn. In the second phase, back-substitute starting from 1=rk1 = r_k (the last non-zero ) upwards, substituting previous expressions to solve for xx and yy. The coefficients are updated iteratively: initialize s0=1s_0 = 1, s1=0s_1 = 0, then for each step i2i \geq 2, si=si2qisi1s_i = s_{i-2} - q_i s_{i-1}, where qiq_i is the at that step; the final sks_k gives xx. Consider the example of finding the inverse of 5 17. Apply the :
17=35+217 = 3 \cdot 5 + 2,
5=22+15 = 2 \cdot 2 + 1,
2=21+02 = 2 \cdot 1 + 0.
Thus, gcd(5,17)=1\gcd(5, 17) = 1. Now back-substitute:
1=5221 = 5 - 2 \cdot 2,
but 2=17352 = 17 - 3 \cdot 5, so
1=52(1735)=5217+65=752171 = 5 - 2 \cdot (17 - 3 \cdot 5) = 5 - 2 \cdot 17 + 6 \cdot 5 = 7 \cdot 5 - 2 \cdot 17.
Hence, x=7x = 7 and y=2y = -2, and 57=351(mod17)5 \cdot 7 = 35 \equiv 1 \pmod{17}, confirming 7 as the inverse.
The following pseudocode implements the recursive version, returning the gcd dd, xx, and yy:

function extended_gcd(a, n): if n == 0: return a, 1, 0 d, s1, t1 = extended_gcd(n, a % n) s = t1 t = s1 - (a // n) * t1 return d, s, t

function extended_gcd(a, n): if n == 0: return a, 1, 0 d, s1, t1 = extended_gcd(n, a % n) s = t1 t = s1 - (a // n) * t1 return d, s, t

To compute the inverse, call extended_gcd(a, n); if d=1d = 1, the inverse is smodns \mod n. The time complexity of the extended Euclidean algorithm is O(logmin(a,n))O(\log \min(a, n)), matching the standard Euclidean algorithm due to the logarithmic number of division steps.

Euler's Theorem Method

Euler's theorem provides a method for computing the modular multiplicative inverse of an integer aa modulo nn when gcd(a,n)=1\gcd(a, n) = 1. The theorem states that if aa and nn are coprime, then aϕ(n)1(modn)a^{\phi(n)} \equiv 1 \pmod{n}, where ϕ(n)\phi(n) is Euler's totient function. From this congruence, it follows that aϕ(n)1a1(modn)a^{\phi(n) - 1} \equiv a^{-1} \pmod{n}, since multiplying both sides by a1a^{-1} (which exists under the coprimality condition) yields the identity. To apply this method, first compute ϕ(n)\phi(n), defined as ϕ(n)=npn(11p)\phi(n) = n \prod_{p \mid n} \left(1 - \frac{1}{p}\right), where the product is over the distinct prime factors pp of nn. Then, calculate aϕ(n)1modna^{\phi(n) - 1} \mod n using efficient algorithms, such as binary exponentiation, which reduces the computational complexity to O(log(ϕ(n)))O(\log(\phi(n))) multiplications modulo nn. This approach leverages the group structure of the units modulo nn, whose order is ϕ(n)\phi(n), but focuses practically on exponentiation rather than group-theoretic operations. For example, consider finding the inverse of 3 modulo 10. Since gcd(3,10)=1\gcd(3, 10) = 1 and ϕ(10)=10(112)(115)=4\phi(10) = 10 \left(1 - \frac{1}{2}\right)\left(1 - \frac{1}{5}\right) = 4, compute 341=33=277(mod10)3^{4-1} = 3^3 = 27 \equiv 7 \pmod{10}. Verifying, 3×7=211(mod10)3 \times 7 = 21 \equiv 1 \pmod{10}, confirming that 7 is the inverse. While theoretically elegant due to its connection to the totient function, this method can be inefficient for large nn without optimized , as ϕ(n)\phi(n) may still be substantial and require of nn upfront. It remains valuable for theoretical analysis and cases where is preferred over other techniques.

Illustrative Examples

Basic Numerical Examples

To illustrate the concept of a modular multiplicative inverse, consider the case of finding the inverse of 7 26. Since gcd(7,26)=1\gcd(7, 26) = 1, an inverse exists, and using the yields 15 as the solution, as 7×15=1051(mod26)7 \times 15 = 105 \equiv 1 \pmod{26}. To verify, compute the product and reduce: 105÷26=4105 \div 26 = 4 1, confirming 1051(mod26)105 \equiv 1 \pmod{26}. In contrast, the 4 has no modular multiplicative inverse 6, because gcd(4,6)=21\gcd(4, 6) = 2 \neq 1. This violates the existence condition, rendering the congruence 4x1(mod6)4x \equiv 1 \pmod{6} unsolvable for any xx, as the does not divide 1. For small moduli, the inverses of numbers coprime to the modulus can be tabulated systematically. The following table lists the modular multiplicative inverses 5 (where gcd(a,5)=1\gcd(a, 5) = 1 for a=1,2,3,4a = 1, 2, 3, 4):
aaa1(mod5)a^{-1} \pmod{5}Verification
111×1=11(mod5)1 \times 1 = 1 \equiv 1 \pmod{5}
232×3=61(mod5)2 \times 3 = 6 \equiv 1 \pmod{5}
323×2=61(mod5)3 \times 2 = 6 \equiv 1 \pmod{5}
444×4=161(mod5)4 \times 4 = 16 \equiv 1 \pmod{5}
These pairs are derived from the multiplication table modulo 5, highlighting the symmetry where distinct inverses are mutual.

Advanced Applications in Coding

In Reed-Solomon codes, defined over finite fields GF(2^m), modular multiplicative inverses play a crucial role in decoding processes, particularly for computing syndromes and correcting errors. These codes treat as evaluated at elements of the field, with the generator having roots at consecutive powers of a primitive element α. During decoding, syndromes are calculated as S_i = R(α^i), where R(x) is the received ; subsequent steps, such as determining error locations and values, require field divisions, which are implemented via multiplication by inverses. In GF(2^m), inverses are computed efficiently using the applied to modulo the field's irreducible , ensuring operations remain within the field structure. A historical advancement in this area is the Berlekamp-Massey algorithm, developed in 1969, which iteratively finds the shortest matching a sequence of syndromes, relying on multiplicative inverses to update coefficients and normalize the error-locator polynomial σ(x). This algorithm is essential for efficient decoding of Reed-Solomon codes, as it locates multiple errors in O(t^2) time, where t is the error-correcting capability, with inverses ensuring precise coefficient adjustments during iterations. Consider a practical example in GF(16), constructed with the x^4 + x + 1 = 0 over GF(2), where α is a primitive element satisfying α^4 = α + 1. For a (15,13) Reed-Solomon code capable of correcting a single (t=1), suppose the received R(x) yields syndromes S_1 = α^3 and S_2 = α^4 after evaluation at α and α^2. The location X_1 is given by X_1 = S_2 \cdot S_1^{-1}, and the value Y_1 = S_1 \cdot X_1^{-1}. To compute S_1^{-1} = (α^3)^{-1}, apply the to the representation of α^3 (which is x^3 the irreducible) and the field modulus x^4 + x + 1. The steps involve repeated division and back-substitution: first, divide x^4 + x + 1 by x^3 to get x and x + 1; continue until the GCD is 1, yielding coefficients s and t such that s \cdot (α^3) + t \cdot (α^4 + α + 1) = 1, so s(α) = (α^3)^{-1} = α^{12}. With X_1 = α^4 \cdot α^{12} = α^1 and Y_1 computed similarly as α^2, the decoder subtracts Y_1 from R(x) at position X_1, correcting the single and recovering the original codeword. This demonstrates how inverses enable targeted correction in extensions.

Practical Applications

Cryptography and Security

The modular multiplicative inverse is fundamental to the RSA cryptosystem, introduced in 1978, where it enables the generation of the private key from the public key components. In RSA, a user selects two large primes pp and qq, computes the modulus n=p×qn = p \times q, and chooses a public exponent ee coprime to ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1). The private exponent dd is then the modular inverse of ee modulo ϕ(n)\phi(n), satisfying e×d1(modϕ(n))e \times d \equiv 1 \pmod{\phi(n)}. This inverse allows decryption of a ciphertext cc (obtained as memodnm^e \mod n for plaintext mm) via m=cdmodnm = c^d \mod n. For illustration, consider primes p=3p=3 and q=11q=11, so n=33n=33 and ϕ(33)=20\phi(33)=20. With public exponent e=3e=3 (coprime to 20), the private exponent is d=7d=7 since 3×7=211(mod20)3 \times 7 = 21 \equiv 1 \pmod{20}. To encrypt plaintext m=5m=5, compute ciphertext c=53mod33=125mod33=26c = 5^3 \mod 33 = 125 \mod 33 = 26. Decryption yields 267mod33=526^7 \mod 33 = 5, recovering the original message. This process demonstrates how the inverse ensures reversible encryption in the ring of integers modulo nn. Modular multiplicative inverses also underpin the Diffie-Hellman key exchange protocol from 1976, operating in the multiplicative group modulo a large prime pp. Here, parties agree on pp and a generator gg, then exchange gamodpg^a \mod p and gbmodpg^b \mod p (for private exponents aa and bb); each computes the shared secret (gb)amodp=gabmodp(g^b)^a \mod p = g^{ab} \mod p or symmetrically. Inverses exist for all nonzero elements modulo pp (a field), enabling group operations essential for secure key derivation without direct transmission. The protocol's security stems from the discrete logarithm problem's hardness in this setting. RSA's security relies on the presumed difficulty of factoring nn to recover ϕ(n)\phi(n) and compute the private inverse dd, as inverting ee modulo ϕ(n)\phi(n) without factorization is computationally infeasible for large nn. Without the trapdoor (knowledge of pp and qq), deriving dd requires solving the difficult problem of finding Euler's totient or directly inverting in an unknown modulus. However, Shor's , proposed in 1994, factors nn in time using a quantum computer, potentially breaking RSA by enabling inverse computation. Post-2023 advancements, including optimized implementations, have lowered the barrier: a 2025 Quantum AI analysis estimates RSA-2048 could be factored in under a week with fewer than one million noisy qubits, accelerating the shift to .

Error-Correcting Codes

In linear error-correcting codes defined over the Z/pZ\mathbb{Z}/p\mathbb{Z} (where pp is prime), modular multiplicative inverses play a fundamental role by enabling the solution of linear systems required for . Specifically, these codes operate as subspaces of (Z/pZ)n(\mathbb{Z}/p\mathbb{Z})^n, and decoding often involves computing the s=Hes = H e (where HH is the parity-check matrix and ee is the vector) and solving for ee through matrix operations that rely on field inverses to isolate error locations and values. This field structure ensures that every nonzero element has a unique , facilitating efficient algebraic manipulations essential for practical implementations. Hamming codes exemplify this application, as they are perfect linear codes capable of correcting single over finite fields Fp\mathbb{F}_p. In the binary Hamming(7,4) over GF(2)\mathbb{GF}(2), the parity-check matrix HH consists of all nonzero columns from F23\mathbb{F}_2^3, and the directly identifies the position since field inverses are trivial (the inverse of 1 is 1 2). For extensions to odd primes p>2p > 2, such as Hamming codes over Fp\mathbb{F}_p, decoding requires explicit computation of inverses to resolve parity-check equations; for instance, solving He=sH e = s may involve premultiplying by H1H^{-1} or , where inverses of pivot elements pp determine the vector ee. This generalization enhances performance in non-binary settings, allowing correction of in symbols from larger alphabets. Advancements in low-density parity-check (LDPC) codes further highlight the utility of modular inverses in iterative decoding over non-binary finite fields GF(q)\mathbb{GF}(q). In algorithms like the sum-product algorithm (), check-node and variable-node updates involve convolutions and normalizations over GF(q)\mathbb{GF}(q), where multiplicative inverses are invoked to compute probabilities or messages (e.g., scaling factors in log-domain implementations using fast Fourier transforms over extension fields). Simplified variants, such as the FFT-based and min-max approximations, reduce complexity by a factor of qq while preserving performance close to the full , relying on efficient inverse computations for field multiplications during . These methods achieve near-capacity error correction in high-rate scenarios. Reed-Solomon codes, widely used in storage media (e.g., CDs, DVDs) and digital communications (e.g., QR codes, satellite links), also rely on modular multiplicative inverses in finite fields GF(2m)\mathbb{GF}(2^m). These non-binary cyclic codes correct multiple symbol errors through decoding algorithms like Berlekamp-Massey, which solve key equations using field inverses to find error locator polynomials. In research for beyond-5G systems like 6G, non-binary variants of polar and LDPC codes are proposed for enhanced reliability in control channels, incorporating inverses in polar transform operations and rate-matching to optimize error correction under varying channel conditions.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.