Classical Ciphers: Cryptography - CS 411 / 507 Erkay Savas Sabancı University
Classical Ciphers: Cryptography - CS 411 / 507 Erkay Savas Sabancı University
– a r mod m if m divides a – r.
– m is called the modulus
– r is called the remainder
–a=q·m+r 0r<m
07/29/2021 Erkay Savas 2
Ring
Definition: The ring m consists of
• Example: m = 9
– 9 = {0, 1, 2, 3, 4, 5, 6, 7, 8}
– 6 + 8 = 14 mod 9 = 5
– 6 8 = 48 mod 9 = 3
07/29/2021 Erkay Savas 3
Properties of Ring Zm 1/2
• Two operations + and
• Example: Exponentiation in m
– 38 mod 7 = ?
– 38 mod 7 = 6561 mod 7 = 2
since 6561 = 937 7 + 2
07/29/2021 Erkay Savas 7
Arithmetic in m
– 38 = 34 34 = 32 32 32 32
– 38 mod 7
= [(32 mod 7) (32 mod 7) (32 mod 7) (32 mod 7)] mod 7
= 38 mod 7 = 2 2 2 2 mod 7 = 16 mod 7 = 2
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Algorithm:
• Let P = C = K = 26 and x P, y C, k K
• Encryption: y = Ek(x) = x + k mod 26.
• Decryption: x = Dk(y) = y - k mod 26.
07/29/2021 Erkay Savas 9
Shift Cipher
• Remark: The shift cipher is also known as
– Caesar Cipher.
• Example: Let the key be k = 17
– Plaintext:
X = ATTACK = (0,19,19,0,2,10).
– Ciphertext:
Y = (0+17 mod 26, 19+17 mod 26, …)
Y = (17,10,10,17,19,1) = RKKRTB
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
– a n y o r s r u c o f j c z m o i d h e y t h j …
– z g a n y o r s r u c o f j c z m o i d h e y t …
– e m o l p g x y k n r t i f x e h j e m o l s j …
– h j e m o l p g x y k n r t i f x e h j e m o l …
Shifts 1 2 3 4 5 6 7 8
Coincidences 18 17 12 20 21 44 25 16
k1 = 4
• Second sub-ciphertext:
V F Y … …
14 10 9 … …
E O H
k2 = 17
07/29/2021 Erkay Savas 27
Frequency Analysis 2/3
• Third sub-ciphertext:
O K Y … …
15 11 10 … …
E A O … …
k3 = 10
• Fourth sub-ciphertext:
A T O …
14 11 9 …
A T O …
k4 = 0
07/29/2021 Erkay Savas 28
Frequency Analysis 3/3
• Fifth sub-ciphertext:
C R G Q …
12 11 10 9 …
E T I S …
k5 = 24
• Sixth sub-ciphertext:
W F G … …
10 9 9 … …
E N O … …
k6 = 18
07/29/2021 Erkay Savas 29
Finally
• Plaintext
– tworoadsdivergedinayellowwoodandsorryicoul
dnottravelbothandbeonetravelerlongistoodan
dlookeddownoneasfarasicouldtowhereitbentin
theundergrowththentooktheotherasjustasfair
andhavingperhapsthebetterclaimbecauseitwas
grassyandwantedwearthoughasforthatthepassi
ngtherehadwornthemreallyaboutthesameandbot
hthatmorningequallylayinleavesnostephadtro
ddenblackohikeptthefirstforanotherdayyetkn
owinghowwayleadsontowayidoubtedifishouldev
ercomebackishallbetellingthiswithasighsome
whereagesandageshencetworoadsdivergedinawo
odandiitooktheonelesstraveledbyandthathasm
adeallthedifference
07/29/2021 Erkay Savas 30
THE ROAD NOT TAKEN
two roads diverged in a yellow wood,
and sorry I could not travel both
and be one traveler, long I stood
and looked down one as far as I could
to where it bent in the undergrowth;
then took the other, as just as fair,
and having perhaps the better claim,
because it was grassy and wanted wear;
though as for that the passing there
had worn them really about the same,
and both that morning equally lay
in leaves no step had trodden black.
oh, I kept the first for another day!
yet knowing how way leads on to way,
I doubted if I should ever come back.
I shall be telling this with a sigh
somewhere ages and ages hence:
two roads diverged in a wood and I-
I took the one less traveled by,
and that has made all the difference.
07/29/2021 Erkay Savas 31
Substitution Ciphers
• Each letter in the alphabet is replaced (substituted) by
another letter.
• More precisely, a permutation of the alphabet is
chosen and applied to the plaintext.
– The shift and affine ciphers are examples of substitution
ciphers.
• The number of permutations is 26!
• Ciphertext preserves the statistics of the language used
for plaintext,
– the frequency analysis is an effective way of breaking
substitution ciphers (if you know the language statistics)
07/29/2021 Erkay Savas 32
Diffusion & Confusion
• Exhaustive search in cryptanalysis is an efficient method
to break a cryptosystem
– Especially when a relatively small key space is used.
– However, large key space not necessarily guarantees to
provide high cryptographic strength.
– Example: The key space of a substitution cipher is
26! 4 1026 (equivalent to 89-bit keys)
– Statistical properties of the language is preserved in the
ciphertext
• Diffusion property of Shannon requires that changing
one letter in the plaintext result in changes in several
letters of the ciphertext.
07/29/2021 Erkay Savas 33
Diffusion & Block Ciphers
• Hill Cipher: The key is an n n matrix whose entries are
integers in 26.
• Example: Let n = 3 and the key matrix be
1 2 3
K 4 5 6
11 9 8
1 2 3 0
4 5 6 1 (8, 17, 25) mod 26 IRZ
11 9 8 2
22 5 1
1
K 6 17 24
15 13 1
07/29/2021 Erkay Savas 35
Hill Cipher & Diffusion
• If we change one letter in the plaintext, three letters of
the ciphertext will be affected.
• Example: Let the plaintext be “BBC” instead of “ABC”
then the ciphertext
1 2 3 1
4 5 6 1 (9, 21, 10) mod 26 JVK
11 9 8 2
• http://csrc.nist.gov/groups/ST/toolkit/rng/index.html
• https://web.archive.org/web/20160125103112/http://s
tat.fsu.edu/pub/diehard/