+ All Categories
Home > Documents > Modular Arithmetic and the Caesar...

Modular Arithmetic and the Caesar...

Date post: 11-Mar-2021
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
24
Modular Arithmetic and the Caesar Cipher Yan Huang
Transcript
Page 1: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

ModularArithmeticandtheCaesarCipher

YanHuang

Page 2: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Objectives

• Divisibility• PrimeandCompositeNumbers• FundamentalTheoremofArithmetic• ceiling, floor, /, mod• Caesarcipher

Page 3: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

• Thesetofingtegers ℤ = … , −2, −1, 0, 1, 2, … .

• ) divides* if)+ = * forsome+ ∈ ℤ.

• Wewrite)|* todenote) divides*.Wesay) isadivisorof* and* isamultiple of).

Page 4: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),*,. ∈ ℤ

) ), 1 ), )| 0.

Page 5: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),*,. ∈ ℤ

0|) ifandonlyif) = 0.

Page 6: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),*,. ∈ ℤ

) * ⇔ −) * ⇔ )| − *.

Page 7: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),*,. ∈ ℤ

) * and ) . ⇒ )|(* + .).

Page 8: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),*,. ∈ ℤ

) * and * . ⇒ )|..

Page 9: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Divisibility

Forall),* ∈ ℤ

) * and * ) ⇔ ) = ±*.

Page 10: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Primality

: isaprimeif: > 1 andhasnootherpositivedivisorbesides1 and:.

: isacompositeif: > 1 andisnotaprime.

Page 11: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

TheListofPrimes

Page 12: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Fundamentaltheoremofarithmetic

Everynon-zerointeger: canbewrittenas

: = ±<=>? … <@

>A.

where<= < <C < ⋯ < <@ aredistinctprimesandE=, … , E@ arenon-negativeintegers.Moreover,theexpressionisunique.

Page 13: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

DivisionwithRemainder

Let), * ∈ ℤ with * > 0.ThenthereexistuniqueF, G ∈ ℤ suchthat

) = F* + G and0 ≤ G < *.

Page 14: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Floors

Thefloor function,denotedby⌊⋅⌋,isafunctionfromrealnumbersℝ toℤ.Forevery M ∈ ℝ,⌊M⌋ isthegreatestintegerN ≤ M.

⌊M⌋ isuniquelydefinedforeveryM.

Page 15: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Ceilings

Theceilingfunction,denotedby⌈⋅⌉,isafunctionfromrealnumbersℝ toℤ.Forevery M ∈ ℝ,⌈M⌉ isthesmallestintegerN ≥ M.

⌈M⌉ isuniquelydefinedforeveryM.

Page 16: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Themod operator

Let), * ∈ ℤ with * > 0,) = F* + G and0 ≤ G < *.Wedefine

) mod * ≔ G

Page 17: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

Themod operator(GeneralizedDefinition)

Let), * ∈ ℤ,wedefine

) mod * ≔ ) − *⌊)/*⌋

Page 18: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

DayinaWeek

September1,2016isThursday.WhatdayisOct1,2016?

Page 19: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

MessagesEncoding&Decoding

• Percharacter:

encodeC :: Char -> IntencodeC =

decodeC :: Int -> ChardecodeC =

Page 20: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

MessagesEncoding&Decoding

• Percharacter:

encodeC :: Char -> IntencodeC ‘A’ = 0encodeC ‘B’ = 1...encodeC ‘Z’ = 25

decodeC :: Int -> ChardecodeC 0 = ‘A’decodeC 1 = ‘B’...decodeC 25 = ‘Z’

Verytediousandunscalable.Doyouhavebetterideas?

Page 21: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

MessagesEncoding&Decoding

• Dealingwithmulti-charactermessages

encode :: [Char] -> [Int]encode m = map encodeC m

encode :: [Char] -> [Int]encode = map encodeC

Point-freeform

Page 22: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

CaesarCipher(ShiftCipher)

Encryption:V = W + X mod 26

Decryption:W = V − X mod 26

TheencryptionkeyInputcharacter

Page 23: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

ImplementingCaesarCipher

caesarC :: Int -> Int -> IntcaesarC k c = (c + k) mod 26

caesar :: Int -> [Int] -> [Int]caesar = map . caesarC

Page 24: Modular Arithmetic and the Caesar Cipherhomes.sice.indiana.edu/yh33/Teaching/I231-2016/lectures/...Caesar Cipher (Shift Cipher) Encryption: V = W +X mod 26 Decryption: W = V −X mod

ImplementingCaesarCipher

caesarDC :: Int -> Int -> IntcaesarDC k c = (c - k) mod 26

caesar :: Int -> [Int] -> [Int]caesar = map . caesarDC


Recommended