0% found this document useful (0 votes)
161 views3 pages

Modular Arithmetic PDF

The document discusses modular arithmetic and modular exponentiation. It explains that the modulo operation finds the remainder when one number is divided by another. It then provides properties of modular arithmetic and shows how modular exponentiation can be used to quickly calculate large exponential expressions by breaking them down into modular multiplications. Specifically, it demonstrates calculating A^B mod C for both when B is a power of 2 and for any value of B by expressing B in binary and using successive squaring.

Uploaded by

Keyur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views3 pages

Modular Arithmetic PDF

The document discusses modular arithmetic and modular exponentiation. It explains that the modulo operation finds the remainder when one number is divided by another. It then provides properties of modular arithmetic and shows how modular exponentiation can be used to quickly calculate large exponential expressions by breaking them down into modular multiplications. Specifically, it demonstrates calculating A^B mod C for both when B is a power of 2 and for any value of B by expressing B in binary and using successive squaring.

Uploaded by

Keyur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MODULAR ARITHMETIC

When one number is divided by another, the modulo operation finds the remainder. It is
denoted by the % symbol.
PROPERTIES
1. (a+b)%c=(a%c+b%c)%c
2. (a∗b)%c=((a%c)∗(b%c))%c
3. (a−b)%c=((a%c)−(b%c)+c)%c
4. (a/b)%c=((a%c)∗(b−1%c))%c
Note​: In the last property, b​-1​ is the multiplicative modulo inverse of b and c.

MODULAR EXPONENTIATION

Often we want to calculate ​A^B mod C​ for ​large values of B.​


These huge values cause our calculators and computers to return ​overflow errors​.
Suppose we want to calculate ​2^90 mod 13,

(2^​90​ )%C=( 2^​50​ * 2^​40)%C

2^50​ mod 13 = ​1125899906842624​ mod 13 = 4


2^40​ mod 13 = ​1099511627776​ mod 13 = ​3

2^90​ mod 13 = (​2^50 * 2^40​) mod 13

2^90​ mod 13 = (​2^50​ mod 13 * ​2^40​ mod 13) mod 13

2^90​ mod 13 = ( ​4​ * ​3​ ) mod 13

2^90​ mod 13 = ​12​ mod 13

2^90​ mod 13 = ​12

​How can we calculate A^B mod C quickly if B is a power of 2 ?

Using modular multiplication rules:

i.e. ​A^2​ mod C = ​(A * A)​ mod C = (​(A mod C)​ * ​(A mod C)​) mod C

7^1​ mod 13 = ​7

7^2​ mod 13 = (​7^1 *7^1​) mod 13 = (​7^1 mod 13 * 7^1 mod 13​) mod 13

7^2​ mod 13 = (​7 *7​) mod 13 = ​49​ mod 13 = ​10


7^4​ mod 13 = (​7^2 *7^2​) mod 13 = (​7^2 mod 13​ * ​7^2 mod 13​) mod 13

7^4​ mod 13 = (​10 * 10​) mod 13 = ​100​ mod 13 = ​9

7^8​ mod 13 = (​7^4 * 7^4​) mod 13 = (​7^4 mod 13​ * ​7^4 mod 13​) mod 13

7^8​ mod 13 = (​9 * 9​) mod 13 = ​81​ mod 13 = ​3

We continue in this manner, substituting previous results into our equations.

...after 5 iterations we hit:

7^256​ mod 13 = (​7^128 * 7^128​) mod 13 = (​7^128 mod 13​ * ​7^128 mod 13​) mod 13

7^​256​ mod 13 = (​3 * 3​) mod 13 = ​9​ mod 13 = ​9

7^256 mod 13 = 9

​How can we calculate A^B mod C quickly for any B ?

​ ​mod 19
Eg. ​5117

117=1110101 in binary
117=2​0 ​+ 2​2 ​+2​4​+2​5 ​+2​6
5​117 ​mod 19 = 5​(1+4+16+32+64) ​mod 19
5​117 ​mod 19 = (5​1​ * 5​4​ * 5​16​ * 5​32​ *5​64 ​) mod 19

5^1​ mod 19 = ​5

5^2​ mod 19 = (​5^1 * 5^1​) mod 19 = (​5 * 5​) mod 19 = ​25​ mod 19 ​= 6

5^4​ mod 19 = (​5^2 * 5^2​) mod 19 = (​6 * 6​) mod 19 = ​36​ mod 19=​ 17

5^8​ mod 19 = (​5^4 * 5^4​) mod 19 = (​17 * 17​) mod 19 = ​289​ mod 19 = 4

5^16​ mod 19 = (​5^8 * 5^8​) mod 19 = (​5^8 mod 19 * 5^8 mod 19​) mod 19

Similarly

5^16 mod 19 = 16

5^32 mod 19 = 9
5^64 mod 19 = 5

5^117​ mod 19 = ( ​5^1 * 5^4 * 5^16 * 5^32 * 5^64​) mod 19

5^117​ mod 19 = ( ​5^1 mod 19 * 5^4 mod 19 * 5^16 mod 19 * 5^32 mod 19 * 5^64 mod

19​) mod 19

5^117​ mod 19 = ( ​5 * 17 * 16 * 9 * 5​ ) mod 19

5^117​ mod 19 = ​61200​ mod 19 = ​1

5^117 mod 19 = 1

​Here are some links to questions

Problem 1

Problem 2

Problem 3

Problem 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy