Modular Multiplication#
Modular multiplication involves multiplying two numbers and then taking the remainder when the result is divided by the modulus.
The formula for modular multiplication of two numbers \(a\) and \(b\) with modulus \(m\) is:
Steps:
Multiply the numbers \(a\) and \(b\).
Apply the modulus \(m\) to find the remainder.
Functions#
Show code cell source
import sympy as sp
from sympy import *
from math import gcd
import random
def modular_multiplication(a, b, modulus):
result = (a * b) % modulus
print(f"{a} * {b} ≡ {result} (mod {modulus})")
return result
Examples#
Find \((23 \times 7)~mod~26\)#
a = 23
b = 7
modulus = 26
result = modular_multiplication(a, b, modulus)
23 * 7 ≡ 5 (mod 26)
Explanation
To find the result of ( 23 \times 7 ) modulo ( 26 ), follow these steps:
Perform the multiplication:
Find the remainder when divided by the modulus:
Now, calculate the remainder when ( 161 ) is divided by ( 26 ):
Express the division:
The remainder is the result of the modulo operation:
Therefore:
Finding \((182 \times 39)~mod~8\)#
a = 182
b = 39
modulus = 8
result = modular_multiplication(a, b, modulus)
Explanation
To find the result of ( 182 \times 39 ) modulo ( 8 ), follow these steps:
Perform the multiplication:
Find the remainder when divided by the modulus:
Now, calculate the remainder when ( 7104 ) is divided by ( 8 ):
Express the division:
The remainder is the result of the modulo operation:
Therefore:
Finding \((123 \times 291)~mod~39\)#
a = 123
b = 291
modulus = 39
result = modular_multiplication(a, b, modulus)
123 * 291 ≡ 30 (mod 39)
Explanation
To find the result of ( 123 \times 291 ) modulo ( 39 ), follow these steps:
Perform the multiplication:
Find the remainder when divided by the modulus:
Now, calculate the remainder when ( 35853 ) is divided by ( 39 ):
Express the division:
The remainder is the result of the modulo operation:
Therefore: