The Wayback Machine - https://web.archive.org/web/20250613171806/https://www.geeksforgeeks.org/modular-multiplication/
Open In App

Modular Multiplication

Last Updated : 26 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Modular arithmetic, or clock arithmetic, is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value

  1. This mathematical concept is widely used in various fields such as computer science, cryptography, number theory, and even everyday situations like clock time calculations.
  2. Modular arithmetic is used in systems where values are cyclical or repetitive.

Modular multiplication is a specific operation within modular arithmetic. Given two integers a and b, and a modulus n, the modular multiplication of a and b is defined as:

(a × b) mod n

Example a = 5, b = 3, n = 11
(a x b) mod n = (5 x 3) mod 11 = 4

This operation yields the remainder when the product of a and b is divided by n. The result is always an integer between 0 and n−1.

Basic Principles of Modular Multiplication

The Modulo Operation

The modulo operation, denoted by \mod, returns the remainder of the division of one number by another. For example, 7 mod 3 results in 1 because when 7 is divided by 3, the remainder is 1. This operation is at the core of modular arithmetic.

Properties of Modular Multiplication

Modular multiplication shares several properties with regular multiplication, which makes it a useful tool in various mathematical and computational contexts.

  • Commutativity: (a × b) mod n = (b × a) mod n. The order of multiplication does not affect the result.
  • Associative: ((a × b) ×c) mod n = (a× (b × c)) mod n. The way in which numbers are grouped during multiplication does not affect the outcome.
  • Distributivity: (a × (b+c)) mod n= ((a×b) mod n +(a × c) mod n) mod n. This property links multiplication and addition in modular arithmetic.

Calculating Modular Multiplication

To calculate modular multiplication, follow these steps:

  1. Multiply the two integers a and b.
  2. Divide the product by the modulus n.
  3. The remainder of this division is the result of the modular multiplication.

For example, to calculate (4 ×7) mod 5:

  1. Multiply 4 by 7 to get 28.
  2. Divide 28 by 5, which equals 5 with a remainder of 3.
  3. Thus, 28 mod 5= 3, so (4×7) mod 5= 3.

Interesting Properties of Modular Multiplication

1. (a x b) mod m = ((a mod m) x (b mod m)) mod m 
2. (a x b x c) mod m = ((a mod m) x (b mod m) x (c mod m)) mod m 

The same property holds for more than three numbers.

Example 1: 
Find the remainder of 15 x 17 x 19 when divided by 7. 
Solution: 

On dividing 15 by 7 we get 1 as remainder. 
On dividing 17 by 7 we get 3 as remainder. 
On dividing 19 by 7 we get 5 as remainder. 
Remainder of the expression (15 x 17 x 19)/7 will be equal to (1 x 3 x 5)/7. 
Combined remainder will be equal to remainder of 15/7 i.e. 1. 

Example 2: Find the remainder of 1421 x 1423 x 1425 when divided by 12. 

Solution: 

On dividing 1421 by 12 we get 5 as remainder. 
On dividing 1423 by 12 we get 7 as remainder. 
On dividing 1425 by 12 we get 9 as remainder. 
Rem [(1421 x 1423 x 1425)/12] = Rem [(5 x 7 x 9)/12] 
Rem [(35 x 9)/12] = Rem [(11 x 9)/12] 
Rem [99/12] = 3. 

Proof of Modular Multiplication Property

Proof: If we prove for two numbers, then we can easily generalize it. Let us see proof for two numbers. 

Let a % m = r1
and b % m = r2

Then a and b can be written as (using quotient
theorem). Here q1 is quotient when we divide
a by m and r1 is remainder. Similar meanings
are there for q2 and r2
a = m x q1 + r1
b = m x q2 + r2

LHS = (a x b) % m
= ((m x q1 + r1 ) x (m x q2 + r2) ) % m
= (m x m x q1 x q2 + m x q1 x r2 + m x q2 x r1 + r1 x r2 ) % m
= (m x (m x q1 x q2 + q1 x r2 + q2 x r1) + r1 x r2 ) % m


We can eliminate the multiples of m when
we take the mod m.
LHS = (r1 x r2) % m

RHS = (a % m x b % m) % m
= (r1 x r2) % m

Hence, LHS = RHS

Applications of Modular Multiplication

Modular multiplication has several applications in various domains:

  1. Cryptography: It is crucial in algorithms like RSA, where modular arithmetic ensures that encryption and decryption processes are secure and efficient.
  2. Hash Functions: In computer science, modular multiplication is often used in hashing algorithms, which are used to map data of arbitrary size to fixed-size values.
  3. Digital Signal Processing: Modular arithmetic is used in algorithms that process signals, images, and other forms of digital data.
  4. Gaming and Simulations: Modular arithmetic is used to create cyclic behaviors, such as rotating objects or managing time cycles in simulations and video games.

Unsolved Problems

Problem 1: Calculate the remainder of (35× 46) mod7.

Problem 2: Find the remainder when (84× 123× 45) mod19 is calculated.

Problem 3: Determine (567× 789) mod13.

Problem 4: Compute (247× 358× 469) mod17.

Problem 5: Solve for the remainder of (723× 89) mod29.

Problem 6: Find (1024× 2048) mod31.

Problem 7: Calculate (987× 654× 3 21) mod23.

Problem 8: Determine the remainder of (15× 27× 33) mod9.

Problem 9: Solve for (91× 72× 43) mod11.

Problem 10: Compute (556× 444× 332) mod13.

Related article

Modular multiplicative inverse
Modular arithmetic


Next Article

Similar Reads