0% found this document useful (0 votes)
406 views

Modular Arithmetic

Modular arithmetic involves calculating remainders when dividing integers by a modulus n. Two numbers are congruent modulo n if they have the same remainder when divided by n. Modular arithmetic has important properties like commutativity, associativity, and distributivity that make it useful in cryptography. Exponentiation in modular arithmetic is done by repeated multiplication, applying the modulus at each step to keep values small.

Uploaded by

mani chand
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
406 views

Modular Arithmetic

Modular arithmetic involves calculating remainders when dividing integers by a modulus n. Two numbers are congruent modulo n if they have the same remainder when divided by n. Modular arithmetic has important properties like commutativity, associativity, and distributivity that make it useful in cryptography. Exponentiation in modular arithmetic is done by repeated multiplication, applying the modulus at each step to keep values small.

Uploaded by

mani chand
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Modular Arithmetic

• Several important cryptosystems make use


of modular arithmetic.
• calculation is always in the range 0 – n
where n is the modulus.
• To calculate the value of a mod n,
– you take away as many multiples of n as
possible until you are left with a reminder
between 0 and n-1.
– a is an integer, n is +ve integer
If a is a negative number then you add as
many multiples of n as necessary to get an
answer in the range 0 – n-1.
a mod n = (qn + r) mod n
-a mod n = (b – wn) mod n
Examples
17 mod 5 = 2 7 mod 11 = 7
20 mod 3 = 2 11 mod 11 = 0
-3 mod 11 = 8 -1 mod 11 = 10
25 mod 5 = 0 -11 mod 11 = 0
• Two numbers a and b are said to be
“congruent modulo n” if
(a mod n) = (b mod n)  a ≡ b(mod n)
• The difference between a and b will be a
multiple of n
So a-b = kn for some value of k
E.g: 4  9  14  19  -1  -6 mod 5
73  4(mod 23); 21  -9(mod 10)
If a  0 (mod n), then n|a.
Properties of Congruences
1. a  b (mod n) if n|(a-b)
2. a  b (mod n) implies b  a (mod n)
3. a  b (mod n) and b  c (mod n) imply a  c (mod n)
4. (a + b )  (a + c) mod n; then b  c mod n
5. (a * b )  (a * c) mod n; then b  c mod n
a  b (mod n) if n|(a-b)
Proof of 1.
If n|(a-b), then (a-b) = kn for some k. Thus,
we can write
a = b + kn. Therefore,
(a mod n) = (remainder when b + kn is
divided by n) = (remainder when b is
divided by n) = (b mod n).
(a + b )  (a + c) mod n;
then b  c mod n

Proof of 4:

(-a + (a + b ) ) (-a + (a + c)) mod n;


(-a + a + b)  (-a + a + c) mod n
.`. b = c mod n
(a * b )  (a * c) mod n;
then b  c mod n
Proof of 5:

(a-1 * (a * b ) ) (a-1 * (a * c)) mod n;


(a-1 + a + b)  (a-1 * a * c) mod n
.`. b = c mod n
Examples
23  8 (mod 5) because 23 -8 =15 = 5x3
-11  5 (mod 8) because -11-5 = -16 = 8x(-2)
81  0 (mod 27) because 81-0=81 = 27x3
Properties of Modular Arithmetic
1. [(a mod n) + (b mod n)] mod n = (a + b) mod n
2. [(a mod n) - (b mod n)] mod n = (a - b) mod n
3. [(a mod n) x (b mod n)] mod n = (a x b) mod n
Proof of 1.
(a + b) mod n = ((a mod n) + (b mod n) ) mod n
Let (a mod n) = Ra
(b mod n) = Rb.
Then, we can write
a = Ra + jn for some integer j
b = Rb + kn for some integer k.
(a + b) mod n = (Ra + jn + Rb + kn) mod n
= [Ra + Rb + (k + j) n] mod n
= (Ra + Rb) mod n
= [(a mod n) + (b mod n)] mod n
Examples
11 mod 8 = 3;
15 mod 8 = 7
[(11 mod 8 ) + (15 mod 8)] mod 8 = (3 + 7) mod 8 = 2
(11 + 15) mod 8 = 26 mod 8 = 2
[(11 mod 8 ) - (15 mod 8)] mod 8 = -4 mod 8 = 4
(11 - 15) mod 8 = -4 mod 8 = 4
[(11 mod 8 ) x (15 mod 8)] mod 8= 21 mod 8 = 5
(11 x 15) mod 8 = 165 mod 8 = 5
Properties of Modular Arithmetic
Property Expression
Cummitative Laws (w + x) mod n = (x + w) mod n
(w x x) mod n = (x x w) mod n

Associative Laws [(w + x) + y] mod n = [w + (x + y)] mod n


[(w x x) x y] mod n = [w x (x x y)] mod n

Distributive Law [w x (x + y)] mod n = [(w x x) + (w x y)] mod n

Identities (0 + w) mod n = w mod n


(1 x w) mod n = w mod n
Additive Inverse (-w) -w mod n = (a – b) mod n;
where a – b = -w and n | b
Exponentiation
• Exponentiation is done by repeated
multiplication, as in ordinary arithmetic.
7
To find (11 mod13) do the followings
11 121  4(mod13)
2

11 (11 )  4  3(mod13)
4 2 2 2

11 11 4  3  132  2(mod13)


7
A good thing about modular arithmetic is
that the numbers you are working with will
be kept relatively small. At each stage of an
algorithm, the mod function should be
applied.
Thus to multiply 39 * 15 mod 11 we first
take mods to get
39 mod 11 = 6 and 15 mod 11= 4
The multiplication required is now
6*4 mod 11 = 24 mod 11 = 2

You might also like