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

Modular Addition

Last Updated : 21 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Modular addition is a fundamental concept in number theory and computer science, widely used in cryptography, coding theory, and digital signal processing. It involves performing addition within the confines of a modulus, where numbers wrap around upon reaching a certain value. This article explores the definition, properties, and applications of modular addition in engineering.

What is Modular Addition?

Modular addition involves adding two numbers and then taking the remainder when the sum is divided by a modulus. For integers a and b and a positive integer n(the modulus), the modular addition of a and b is given by:

(a + b) mod n

Modular Addition Example

For a = 7, b = 5, and n = 6:

(7 + 5) mod 6 = 12 mod 6 = 0

Properties of Modular Addition

Modular addition has several important properties that make it useful in various applications:

1. Commutative Property

(a + b) mod n = (b + a) mod n

Example:

(7 + 5) mod 6

= 12 mod 6

= 0

(5 + 7) mod 6

= 12 mod 6

= 0

2. Associative Property

(a + (b + c)) mod n = ((a + b) + c) mod n

Example:

(7 + (5 + 4) mod 6

= (7 + 9) mod 6

= 16 mod 6

= 4

3. Identity Element

The identity element for modular addition is 0:

(a + 0) mod n = a mod n

Example:

(7 + 0) mod 6

= 7 mod 6

= 1

4. Inverse Element

For each integer a in modular arithmetic, there exists an inverse element – a such that:

(a + (-a)) mod n = 0

Example:

For a = 5 and n = 6:

(5 + (-5)) mod 6

= 0

Applications of Modular Addition

1. Cryptography

Modular addition is essential in cryptographic algorithms, particularly in symmetric key cryptography and public-key cryptosystems. It ensures that operations remain within a fixed range, enhancing security.

2. Hash Functions

In computer science, hash functions use modular addition to produce fixed-size hash values from arbitrary data, ensuring efficient data retrieval and storage.

3. Error Detection and Correction

Modular arithmetic is used in error detection and correction codes, such as checksums and cyclic redundancy checks (CRCs), to detect and correct errors in data transmission.

4. Digital Signal Processing

In digital signal processing, modular addition helps in implementing algorithms that process digital signals efficiently, especially in systems with fixed word sizes.

5. Computer Graphics

Modular arithmetic is used in computer graphics to handle color values and coordinate transformations within a bounded range.

Conclusion – Modular Addition

Modular addition is a crucial operation in modular arithmetic, offering properties like commutativity, associativity, and the existence of identity and inverse elements. Its applications span cryptography, hash functions, error detection, digital signal processing, and computer graphics, making it an essential tool in various fields.

FAQs on Modular Addition

What is modular addition?

Modular addition involves adding two numbers and taking the remainder when the sum is divided by a modulus.

How is modular addition used in cryptography?

Modular addition ensures that operations remain within a fixed range, enhancing the security of cryptographic algorithms like RSA.

What are the properties of modular addition?

Modular addition is commutative, associative, and has identity and inverse elements.

Can you give an example of modular addition in digital signal processing?

In FFT algorithms, modular addition helps handle signal indexing and wrap-around effects efficiently.

Why is modular addition important in computer graphics?

It is used to handle color values and coordinate transformations within a bounded range, ensuring values stay within screen dimensions.


Previous Article
Next Article

Similar Reads

Modular Exponentiation (Power in Modular Arithmetic)
Given three numbers x, y and p, compute (xy) % p. Examples : Input: x = 2, y = 3, p = 5 Output: 3 Explanation: 2^3 % 5 = 8 % 5 = 3. Input: x = 2, y = 5, p = 13 Output: 6 Explanation: 2^5 % 13 = 32 % 13 = 6.Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. We have discussed recursive and iterative solutions for powe
9 min read
Number of solutions to Modular Equations
Given A and B, the task is to find the number of possible values that X can take such that the given modular equation (A mod X) = B holds good. Here, X is also called a solution of the modular equation. Examples: Input : A = 26, B = 2Output : 6Explanation:X can be equal to any of {3, 4, 6, 8, 12, 24} as A modulus any of these values equals 2 i. e.,
13 min read
Modular Exponentiation of Complex Numbers
Given four integers A, B, K, M. The task is to find (A + iB)K % M which is a complex number too. A + iB represents a complex number. Examples: Input : A = 2, B = 3, K = 4, M = 5 Output: 1 + i*0 Input : A = 7, B = 3, K = 10, M = 97 Output: 25 + i*29 Prerequisite: Modular Exponentiation Approach: An efficient approach is similar to the modular expone
7 min read
Modular Multiplication
Below are some interesting properties of Modular Multiplication (a x b) mod m = ((a mod m) x (b mod m)) mod m (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. The above formula is the extended version of the following formula: Example 1: Find the remainder of 15 x 17 x 19 when divide
3 min read
Count array elements having modular inverse under given prime number P equal to itself
Given an array arr[] of size N and a prime number P, the task is to count the elements of the array such that modulo multiplicative inverse of the element under modulo P is equal to the element itself. Examples: Input: arr[] = {1, 6, 4, 5}, P = 7Output: 2Explanation:Modular multiplicative inverse of arr[0](=1) under modulo P(= 7) is arr[0](= 1) its
5 min read
XOR of array elements whose modular inverse with a given number exists
Given an array arr[] of length N and a positive integer M, the task is to find the Bitwise XOR of all the array elements whose modular inverse with M exists. Examples: Input: arr[] = {1, 2, 3}, M = 4Output: 2Explanation:Initialize the value xor with 0:For element indexed at 0 i.e., 1, its mod inverse with 4 is 1 because (1 * 1) % 4 = 1 i.e., it exi
7 min read
Modular multiplicative inverse from 1 to n
Give a positive integer n, find modular multiplicative inverse of all integer from 1 to n with respect to a big prime number, say, 'prime'. The modular multiplicative inverse of a is an integer 'x' such that. a x ? 1 (mod prime) Examples: Input : n = 10, prime = 17 Output : 1 9 6 13 7 3 5 15 2 12 Explanation : For 1, modular inverse is 1 as (1 * 1)
9 min read
Modular multiplicative inverse
Given two integers A and M, find the modular multiplicative inverse of A under modulo M.The modular multiplicative inverse is an integer X such that: A X ? 1 (mod M) Note: The value of X should be in the range {1, 2, ... M-1}, i.e., in the range of integer modulo M. ( Note that X cannot be 0 as A*0 mod M will never be 1). The multiplicative inverse
15+ min read
How to avoid overflow in modular multiplication?
Consider below simple method to multiply two numbers. C/C++ Code #include <iostream> using namespace std; #define ll long long // Function to multiply two numbers modulo mod ll multiply(ll a, ll b, ll mod) { // Multiply two numbers and then take modulo to prevent // overflow return ((a % mod) * (b % mod)) % mod; } int main() { ll a = 12345678
6 min read
Modular Division
Given three positive numbers a, b and m. Compute a/b under modulo m. The task is basically to find a number c such that (b * c) % m = a % m.Examples: Input : a = 8, b = 4, m = 5 Output : 2 Input : a = 8, b = 3, m = 5 Output : 1 Note that (1*3)%5 is same as 8%5 Input : a = 11, b = 4, m = 5 Output : 4 Note that (4*4)%5 is same as 11%5 Following artic
9 min read