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:

\[ (a + b) \mod m \]

Steps:

  1. Add the numbers \(a\) and \(b\).

  2. Take the result and apply the modulus \(m\) to find the remainder.

Functions#

Hide 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:

  1. Perform the addition:

\[ 10 + 17 = 27 \]
  1. Compute the remainder when divided by the modulus:

\[ 27 \div 7 = 3 \text{ remainder } 6 \]
  1. Express the division:

\[ 27 = 7 \times 3 + 6 \]
  1. The remainder is the result of the modulo operation:

\[ 27 \mod 7 = 6 \]

Therefore:

\[ 10 + 17 \equiv 6 \mod 7 \]

Finding \((203 + 17)~mod~10\)#

a = 203
b = 17
modulus = 10

result = modular_addition(a, b, modulus)
203 + 17 ≡ 0 (mod 10)

Finding \((-43 + 128)~mod~26\)#

a = -43
b = 128
modulus = 26

result = modular_addition(a, b, modulus)
-43 + 128 ≡ 7 (mod 26)

Finding \((3028 + 220934)~mod~85\)#

a = 3028
b = 220934
modulus = 85

result = modular_addition(a, b, modulus)
3028 + 220934 ≡ 72 (mod 85)