Modular Addition#
Modular addition involves adding two numbers and then taking the remainder when the result is divided by the modulus.
The formula for modular addition of two numbers \(a\) and \(b\) with modulus \(m\) is:
Steps:
Add the numbers \(a\) and \(b\).
Take the result and 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_addition(a, b, modulus):
result = (a + b) % modulus
print(f"{a} + {b} ≡ {result} (mod {modulus})")
return result
Examples#
Finding \((10 + 17)~mod~7\)#
a = 10
b = 17
modulus = 7
result = modular_addition(a, b, modulus)
10 + 17 ≡ 6 (mod 7)
Explanation
To find the result of ( 10 + 17 ) modulo ( 7 ), follow these steps:
Perform the addition:
Compute the remainder when divided by the modulus:
Express the division:
The remainder is the result of the modulo operation:
Therefore:
Finding \((203 + 17)~mod~10\)#
a = 203
b = 17
modulus = 10
result = modular_addition(a, b, modulus)
203 + 17 ≡ 0 (mod 10)
Explanation
To find the result of ( 203 + 17 ) modulo ( 10 ), follow these steps:
Perform the addition:
Compute the remainder when divided by the modulus:
Express the division:
The remainder is the result of the modulo operation:
Therefore:
Finding \((-43 + 128)~mod~26\)#
a = -43
b = 128
modulus = 26
result = modular_addition(a, b, modulus)
-43 + 128 ≡ 7 (mod 26)
Explanation
To find the result of ( -43 + 128 ) modulo ( 26 ), follow these steps:
Perform the addition:
Compute the remainder when divided by the modulus:
Express the division:
The remainder is the result of the modulo operation:
Therefore:
Finding \((3028 + 220934)~mod~85\)#
a = 3028
b = 220934
modulus = 85
result = modular_addition(a, b, modulus)
3028 + 220934 ≡ 72 (mod 85)
Explanation
To find the result of ( 3028 + 220934 ) modulo ( 85 ), follow these steps:
Perform the addition:
Compute the remainder when divided by the modulus:
Express the division:
The remainder is the result of the modulo operation:
Therefore: