Professional Documents
Culture Documents
by William Stallings
Chapter 3
Classical Encryption
Techniques
© 2017 Pearson Education, Ltd., All rights reserved.
Definitions
Plaintext Ciphertext Enciphering/encrypt
ion
•An original message •The coded message
•The process of converting
from plaintext to
ciphertext
Cryptanalysis Cryptology
•Techniques used for •The areas of
deciphering a message cryptography and
without any knowledge cryptanalysis
of the enciphering details
Symmetric,
single-key, secret- Block cipher
Substitution
key, conventional (b >=2)
encryption
168 2168 = 3.7 1050 2167 µs = 5.9 1036 years 5.9 1030 years
Encryption Scheme Security
أمان نظام التشفير
• Unconditionally secure
• No matter how much time an opponent has, it is impossible for him or her to
decrypt the ciphertext simply because the required information is not there
(information is not enough). (e.g one-time pad)
❑ آمن بدون قيد أو شرط
من المستحيل عليه فك تشفير النص المشفر، • بغض النظر عن مقدار الوقت المتاح للخصم او المهاجم
one-time (على سبيل المثال.)بسبب أن المعلومات المطلوبة غير موجودة (المعلومات ليست كافية
) pad
• Computationally secure
• The cost of breaking the cipher exceeds the value of the encrypted
information.
• The time required to break the cipher exceeds the useful lifetime of the
information.
❑ آمن حسابيا
.• تتجاوز تكلفة كسر التشفير قيمة المعلومات المشفرة
.• يتجاوز الوقت الالزم لكسر التشفير العمر اإلنتاجي للمعلومات
© 2017 Pearson Education, Ltd., All rights reserved.
Substitution Technique
. •
• A shift may be of any amount, so that the general Caesar algorithm is:
C = E(k , p ) = (p + k ) mod 26
• Where k takes on a value in the range 1 to 25; the decryption algorithm is simply:
p = D(k , C ) = (C - k ) mod 26
Brute-Force
Cryptanalysis
of
Caesar Cipher
(This chart can be found on page 75 in the
textbook)
The
key Plai n: ab cde fgh ijk lmn opq rst uvw xyz
Ciph er: DK VQF IBJ WPE SCX HTM YAU OLR GZN
Plai nte xt: i fwe wis hto rep lac ele tte rs
Ciph ert ext : W IRF RWA JUH YFT SDV FSF UUF YA
Language Redundancy and
Cryptanalysis التكرار اللغوي وتحليل الشفرات
➢ human languages are redundant
➢ E.g: "th the s m we sh ll nt wnt"
➢ letters are not equally commonly used
➢ in English E is by far the most common letter
⚫ followed by T,R,N,I,O,A,S
➢ other letters like Z,J,K,Q,X are fairly rare
➢ have tables of single, double & triple letter frequencies for various
languages
➢ اللغات البشرية تكرارية
th the s m we sh ll nt wnt" " :➢ على سبيل المثال
➢ الحروف ليست شائعة االستخدام على قدم المساواة
هو إلى حد بعيد الحرف األكثر شيوعاE ➢ في اللغة اإلنجليزية
S ، A ، O ، I ، N ، R ، T تليها ▪
نادرة إلى حد ماX ، Q ، K ، J ، Z ➢ أحرف أخرى مثل
➢ نمتلك جداول تحتوي على ترددات األحرف المفردة والمزدوجة والثالثية لمختلف اللغات
English Letter Frequencies
N-gram Frequencies
• Digram (Digraph Frequency)
– Two-letter combination
– Most common is th
– th he an in er on re ed nd ha at en es of nt ea ti to
io le is ou ar as de rt ve
• Trigram (Trigraph Frequency)
– Three-letter combination
– Most frequent is the
– the and tha ent ion tio for nde has nce tis oft men
20
Use in Cryptanalysis
• Easy to break because they reflect the frequency data of the original alphabet
• key concept - monoalphabetic substitution ciphers do not change relative letter
frequencies
• calculate letter frequencies for ciphertext
• compare counts/plots against known values
• if Caesar cipher look for common peaks/troughs
– peaks at: A-E-I triple, NO pair, RST triple
– troughs at: JK, X-Z
• for monoalphabetic must identify each letter
– tables of common double/triple letters help
• من السهل كسرها ألنها تعكس بيانات التردد لألبجدية األصلية
االستبدال أحادية األبجدية ترددات الحروف النسبية ال تتغير- • المفهوم الرئيسي
• حساب ترددات الحروف للنص المشفر
• مقارنة األعداد بالقيم المعروفة
قيعان مشتركة/ • إذا كان تشفير قيصر يبحث عن قمم
ثالثيRST ، ال زوج، ثالثيA-E-I : قمم في-
X-Z ، JK : أحواض في-
• ألحادي األبجدية يجب تحديد كل حرف
الثالثية الشائعة تساعد/ جداول األحرف المزدوجة-
Example Cryptanalysis
• given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ
• count relative letter frequencies (see text)
• guess P & Z are e and t
• guess ZW is th and hence ZWP is the
• proceeding with trial and error finally get:
it was disclosed yesterday that several informal but
direct contacts have been made with political
representatives of the viet cong in moscow.
Homework: write program to decrypt above ciphertext
Example Cryptanalysis (cont.)
• One alphabet frequencies: guess P & Z are e and t
• Diagrams and trigrams: frequencies of compound
letters → guess ZW is th and hence ZWP is the
• proceeding with trial and error
UZQSOVUOHXM OPVGPOZPEVSGZWSZOPFPESXUDBM ETSXAIZ
t e e te th t e e t
VUEPHZHM DZSHZOWSFPAPPDTSVPQUZWYM XUUHSX
e t t t h e ee e th
• Treats digrams in the plaintext as single units and translates these units into
ciphertext digrams
• Used as the standard field system by the British Army in World War I and
the U.S. Army and other Allied forces during World War II
A B C D E
F G H I/J K
L M N O P
Q R S T U
V W X Y Z
Encryption
• plaintext is encrypted two letters at a time
1. if a pair is a repeated letter, insert filler like 'X’
Example: p= proof p = proxof pr ox of, if the number of
letter is odd we add another X right at the end to make it
come out even.
2. if both letters fall in the same row, replace each with the
letter to right (wrapping back to start from end)
3. if both letters fall in the same column, replace each with
the letter below it (wrapping to top from bottom).
4. otherwise each letter is replaced by the letter in the
same row and in the column of the other letter of the pair.
Encryption
• Example if the message “the office did not jump at the idea”
• The first step would be to split the message up into pairs, as follows
TH EO FF …….
• Repeated letter ff and the number of letter is odd, the message actually
comes out as:-
• TH EO FX FI CE DI DN OT JU MP AT TH EI DE AX
• TH different column and different row replaced by the letter in the same
row and in the column of the other letter of the pair E(TH) = SI, E(EO) = DP,
E(FX) = HV ……
• FI both letters fall in the same row, replace each with letter to right E(FI) =
GK,
• E(CE) = DA
• DI if both letters fall in the same column, replace each with the letter below it
E(DI) = IO
• You get ciphertext SIDPHVGKDAIOCDTYKTNLDQCDDKEACV
Playfair with Key Matrix
• Fill in letters of keyword (minus duplicates) from
left to right and from top to bottom, then fill in
the remainder of the matrix with the remaining
letters in alphabetic order.
• LC (letters fall in the same column, replace each with the letter below it ) UE
• OM (letters fall in the same row, replace each with letter to right ) NO
• EX (otherwise each letter is replaced by the letter in the same row and in the
column of the other letter of the pair) IU
• NO (letters fall in the same row, replace each with letter to the
left ) OM
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 34
Hill Cipher
• Encryption
– Assign each letter in the plaintext by an index(number)
- C = KP mod 26, where P=plaintext and C=ciphertext
- Matrix K is the key
- If P of size nx1, the key (K) must be of size nxn
• Decryption
- P = K-1 C mod 26, where K-1 is the inverse of the matrix K
-1 1 0
- K.K = I, where I= is the identity matrix
0 1
- Thus, we can decrypt iff gcd(det(K), 26) =1.
- We can decrypt only if the key matrix (K)has an inverse(K-1).
35
How to calculate K-1 for 2x2 matrix?
Example: find K-1 for the
1 2
matrix K=
3 4
= (1x4) – (3x2)=4 – 6= –2
K-1 =
Hill Cipher
−1
det( K )
− 1 1+n K
( ) ( ) n ,n
−
2n
1, n 1 K
38
Hill Cipher - Example
• Example: Encrypt the message “HELLO” by using Hill Cipher with
5 8
the key k=
17 3
• Solution: HE LL OX → 7 4 11 11 14 23
Encryption:
H 7
P1 = =
E 4
5 8 7 35 + 32 67 15 P
C1= = = mod 26 = =
17 3 4 119 + 12 131 1 B
HE → PB
Decryption:
-1 9 2
K =
1 15
9 2 15 135 + 2 137 7 H
P1= = = mod 26 = =
1 15 1 15 + 15 30 4 E
Hill Cipher - Example
• Example: Encrypt the message “HELLO” by using Hill Cipher with
5 8
the key k=
17 3
• Solution: HE LL OX → 7 4 11 11 14 23
Encryption:
L 11
P2 = =
L 11
5 8 11 55 + 88 143 13 N
C2= = = mod 26 = =
17 3 11 187 + 33 220 12 M
LL → NM
(5) Vigenère Cipher
• Best known and one of the simplest polyalphabetic substitution ciphers.
• Each cipher is denoted by a key letter which is the ciphertext letter that
substitutes for the plaintext letter.
العادي
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ
• Decryption simply works in reverse
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Example of Vigenère Cipher
• EXAMPLE :- suppose m = 6 and the keyword is CIPHER. This corresponds to the numerical
equivalent K = {2, 8, 15, 7, 4, 17}. Suppose the plaintext is the string
THISCRYPTOSYSTEMISNOTSECURE
• We convert the plaintext elements to residues modulo 26, write groups of six, and then add
the keyword modulo 26
P= 19 7 8 18 2 17 24 15 19 14 18 24 18 19 4 12 8 18 13 14 19 18 4 2 20 17 4
CIPHER CIPHER CIPHER CIPHER CIP
key 2 8 15 7 4 17 2 8 15 7 4 17 2 8 15 7 4 17 2 8 15 7 4 17 2 8 15
---------------------------------------------------------------------------------------------------------------------
21 15 23 25 6 8 0 ---------------- (plaintext + keyword) mod 26
21 15 23 25 6 8 0 23 8 21 22 15 20 1 191912 9 15 22 8 25 19 22 25 19
The ciphertext: VPXZGIAXIVWPUBTTMJPWIZITWZT
• Decryption:
(ciphertext - keyword) mod 26
(6) One-Time Pad
• Improvement to Vernam cipher proposed by an Army Signal Corp
officer, Joseph Mauborgne
جوزيف موبورن، • تحسين تشفير فيرنام الذي اقترحه ضابط في سالح اإلشارة بالجيش
• Use a random key that is as long as the message so that the key need
not be repeated
• Each new message requires a new key of the same length as the new
message
• Scheme is unbreakable:
• Produces random output that bears no statistical relationship to
the plaintext
• Because the ciphertext contains no information whatsoever about
the plaintext, there is simply no way to break the code
© 2017 Pearson Education, Ltd., All rights reserved.
Difficulties
• The one-time pad offers complete security but, in practice, has
two fundamental difficulties:
• There is the practical problem of making large quantities of
random keys
• Any heavily used system might require millions of random
characters on a regular basis
• Mammoth key distribution problem
• For every message to be sent, a key of equal length is needed by
both sender and receiver
Suppose that a cryptanalyst had managed to find these two keys. Two plausible plaintexts are produced.
How is the cryptanalyst to decide which is the correct decryption (i.e., which is the correct key)? Thus,
there is no way to decide which key is correct and therefore which plaintext is correct.
كيف يقرر محلل التشفير ما هو فك التشفير. يتم إنتاج نصين عاديين معقولين.لنفترض أن محلل التشفير قد تمكن من العثور على هذين المفتاحين
. ال توجد طريقة لتحديد المفتاح الصحيح وبالتالي النص العادي الصحيح، الصحيح (أي ما هو المفتاح الصحيح)؟ وبالتالي
© 2017 Pearson Education, Ltd., All
rights reserved.
Example 2
If the key is "XMCKL" and the message is "HELLO", then the coding would be done
as follows:
The ciphertext to be sent to is "EQNVZ". To decrypt the message, the same process,
but in reverse, is applied to obtain the plaintext. Here the key is subtracted from the
ciphertext, again using modular arithmetic:
Steganography
❑ ثقوب دبوس
• Steganography