You are on page 1of 38

បណ្ឌិត្យសភាបច្ចេកវទ្យាឌ

ិ ជី ថ
ី លកម្ពុជា
Cambodia Academy of Digital and Technology

IV. Cryptographic Coding (Part 1)

Lecturer: Cheat Morokot


1- Introduction to Cryptography
• Cryptography is the science of encrypting and decrypting
information to prevent unauthorized access.
• This is based on methods like encryption, decryption, signing,
generating of pseudo random numbers, etc.

2
1- Introduction to Cryptography
• A message is plaintext (cleartext). The process of disguising a
message in such a way as to hide its substance is encryption.
• An encrypted message is ciphertext. The process of turning
ciphertext back into plaintext is decryption.
• A cipher is an algorithm for performing encryption or decryption.

ciphertext
3
1- Introduction to Cryptography
• There are two schemes:
 Symmetric Key Cryptography
 Asymmetric Key Cryptography.
• Symmetric Key Cryptography relies on a single key for
encryption and decryption of information. And key needs to be
kept secret with both the sender and receiver.
• Asymmetric Key Cryptography uses two different keys for
encryption and decryption. The key for encryption is public key,
and the key for decryption is the private key.

4
2- Symmetric-Key Cryptography
• Symmetric ciphers use the same cryptographic keys for both
encryption of plaintext and decryption of ciphertext.
• Example: Bob wants to send a secret message to Alice. We
observe that they must share knowledge of the secret key k.
Using that secret key, they can both encrypt and decrypt
messages, so Bob and Alice have equal (or symmetric)
knowledge and abilities.

5
2- Symmetric-Key Cryptography
• Type of transforming in classical symmetric key cryptography
can be based on two general principles:
1. Substitution Ciphers: each element in plaintext is mapped
into another element.
 Monoalphabetic Ciphers
o Simple substitution ciphers
o Shift ciphers/ Caesar ciphers, etc.
 Polyalphabetic Ciphers : Vigenère ciphers, Playfair ciphers.
2. Transposition Ciphers: elements in plaintext are rearranged.

6
2- Symmetric-Key Cryptography
• How the plaintext is processed:
 Block cipher: processes the input one block of elements at a
time, producing an output block for each input block
 Stream cipher: processes the input elements continuously,
producing output one element at a time.

7
2.1.1- Caesar Shift Ciphers
• Caesar Shift Cipher, relies on shifting the letters of a message by
an agreed number, the recipient of this message would then shift
the letters back by the same number and obtain the original
message. It is a simplest form of substitution cipher scheme.
• The Caesar cipher is named after Julius Caesar , who used it with
a shift of three to protect messages of military significance.

8
2.1.1- Caesar Shift Ciphers
• Example: Encrypted cipher is given as: j s j r d k f q q n s l g f h
pgwjfpymwtzlmnrrnsjsyqzhnzx

A cipher wheel with an offset of five letters


9
2.1.1- Caesar Shift Ciphers
 Thus j in the ciphertext becomes e in the plaintext, because e
is followed in the alphabet by f,g,h,i,j

 The decrypted message:


“Enermy falling back breakthrough imminent lucius.”

10
2.1.1- Caesar Shift Ciphers

Exercise: Build a cipher wheel, but with an inner wheel that


rotates, and use it to complete the following tasks.
(a) Encrypt the following plaintext using a rotation of 11
clockwise.
“a page of history is worth a volume of logic”
(b) Decrypt the following message, which was encrypted
with a rotation of 7 clockwise.
AOLYLHYLUVZLJYLAZILAALYAOHUAOLZLJYLALZAOHALCLYF
IVKFNBLZZLZ
11
2.1.2- Simple Substitution Ciphers
• Substitution cipher is a method of encrypting by which units
of plaintext are replaced with ciphertext, according to a fixed
system.
• A homophonic cipher is a substitution cipher in which there
may be more than one ciphertext symbol for each plaintext
letter.
• Exercise: Here is an example of a homophonic cipher, where
the more common letters have several possible replacements.

12
2.1.2- Simple Substitution Ciphers

Decrypt the following message.

13
2.1.3- Vigenère Ciphers
• Vigenère ciphers are method of encrypting alphabetic text by
using a series of Caesar ciphers, based on the letters of a
keyword.

• Example: Suppose the keyword is CHANGE, representing the


key K = (3, 8, 1, 14, 7, 5). What is the encrypted form of the
following plaintext
“THEPROOFOFTHEPUDDINGISINTHEEATING”?

14
2.1.3- Vigenère Ciphers
 Solution The letters in positions 1, 7, 13, 19, 25, 31 are
T,O,E,N,T,I, and they are encrypted with a shift of 3, becoming
W,R,H,Q,W,L. The other letters are encrypted in a similar way.
The entire process can be set out as follows.
THEPROOFOFTHEPUDDING...
3 8 1 14 7 5 3 8 1 14 7 5 3 8 1 14 7 5 3 8 . . .
WPFDYTRNPTAMHXVRKNQO...

15
2.1.3- Vigenère Ciphers
Plaintext

Key

16
2.1.3- Vigenère Ciphers
• Exercise: The ciphertext below is the result of encrypting a
message in the Vigenère system, using the keyword
SCRAMBLE. Find the message.
“MKWJAFQCHIUPVPONWHFDRKEFIROFEHGQMRGM”

17
2.1.4- Playfair Ciphers
• Playfair cipher is a manual symmetric encryption technique
and was the first digram substitution cipher.
• The scheme was invented in 1854 by Charles Wheatstone, but
bears the name of Lord Playfair for promoting its use.
• Example: The Playfair square with the keyword PERSONALITY:
P E R S O
N A L I T
Y B C D F
G H K M Q
U V W X Z
18
2.1.4- Playfair Ciphers
• To perform the substitution of Playfair ciphers:
1. If both letters are the same (or only one letter is left), add
"X" after the first letter. Some variants use "Q" instead of "X“.
2. If the letters appear on the same row of table, replace
them with the letters to their immediate right respectively.
3. If the letters appear on the same column of your table,
replace them with the letters immediately below respectively.
4. If the letters are not on the same row or column, replace
them with the letters on the same row respectively but at the
other pair of corners of the rectangle defined by the original pair.
19
2.1.4- Playfair Ciphers
• Example of encryption of the digram OR with five general
cases:

20
2.1.4- Playfair Ciphers
Example: Suppose you receive the following ciphertext, knowing
that the Playfair system has been used and the keyword is
PERSONALITY. What is the plaintext?
“AQLAGCPZQTOLVAMLIYHSISEIHP”
 Solution: The ciphertext broken up into a sequence of digrams
AQ LA GC PZ QT OL VA ML IY HS IS EI HP .
Using the rules in reverse, the corresponding sequence is
TH AN KY OU FO RT HE KI ND ME SX SA GE .
It is clear that the plaintext is:
“THANK YOU FOR THE KIND MESSAGE”.
21
2.1.5- Transposition Ciphers
• Transposition cipher is a method of encryption by which the
positions held by units of plaintext are shifted according to a
regular system, so that the ciphertext constitutes a permutation
of the plaintext.
• It is a cipher in which the letters of the plaintext remain the same,
but their order is rearranged.

22
2.1.5- Transposition Ciphers
• Example: Here is a simple example in which the message is
encrypted in blocks of 25 letters at a time. Take the given 25
letters and arrange them in a 5-by-5 block by writing the
message horizontally on the lines. For example, the first 25
letters of the message
“Now is the time for all good men to come to the aid”

23
2.1.5- Transposition Ciphers
 Solution: It is written as:

Now the cipehrtext is formed by reading the letters down the


columns, which gives the ciphertext:
NTMAO OHELD WEFLM ITOGE SIRON.

24
2.2- Stream Ciphers
• A stream cipher is an encryption algorithm that encrypts 1 bit
or byte of plaintext at a time.
• Stream ciphers combine plain-text bits with a pseudorandom
cipher bits stream with the use of XOR (exclusive-or) operation.
• It is used for encryption of GSM handset to base station
communication

25
2.2.1- Synchronous Stream Ciphers
• In a synchronous stream cipher, the key is independent of the
plaintext or ciphertext.
• The simplest and the most secure type of synchronous stream
cipher, is called the one-time pad.

26
2.2.1- Synchronous Stream Ciphers

• Definition (One-time-pad) Let K := {0, 1}n be the key


space and M := {0, 1}n the message space. (Notice that
K = M) Then the one-time-pad encryption E(k,m) of
message m ∈ M under key k ∈ K is defined as E(k,m) :=
k ⊕ m where ⊕ denotes the bitwise XOR.

27
2.2.1- Synchronous Stream Ciphers
Example: One-time pad encryption.

28
2.2.1- Synchronous Stream Ciphers
Example: One-time pad decryption.

29
2.2.2- Asynchronous Stream Ciphers
• Asynchronous stream cipher can be also called Self-synchronous
stream cipher.
• In asynchronous stream cipher, each key in the key stream
depends on previous plaintext or ciphertext.
• As the crypto text blocks depend on all preceding plaintext
blocks, the statistical analysis of the crypto text is hopefully
more difficult.

30
2.2.2.a- Cipher Block Chaining Mode (CBC)
• CBC mode is about adding XOR each plaintext block to the
ciphertext block that was previously produced.
• As a result, every subsequent ciphertext block depends on the
previous one.
• The first plaintext block is added XOR to a random initialization
vector (commonly referred to as IV).
• The vector has the same size as a plaintext block.
• Mathematical formula for CBC encryption is:
𝐶𝑖 = 𝐸𝑘 (𝑃𝑖 ⊕ 𝐶𝑖−1 )
𝐶0 = 𝐼𝑉
31
2.2.2.a- Cipher Block Chaining Mode (CBC)

32
2.2.2.a- Cipher Block Chaining Mode (CBC)
• Mathematical formula for CBC decryption is:
𝐶𝑖 = 𝐷𝑘 (𝐶𝑖 ) ⊕ 𝐶𝑖−1
𝐶0 = 𝐼𝑉

33
2.2.2.a- Cipher Block Chaining Mode (CBC)
• Example:

34
2.2.2.b- Cipher Feedback Mode (CFB)
• The CFB mode is similar to the CBC mode described above.
• The main difference is that one should encrypt ciphertext data
from the previous round (so not the plaintext block) and then
add the output to the plaintext bits.
• In particular, CFB decryption is almost identical to CBC
encryption performed in reverse:
𝐶𝑖 = 𝐸𝑘 (𝐶𝑖−1 ) ⊕ 𝑃𝑖
𝑃𝑖 = 𝐸𝑘 𝐶𝑖−1 ⊕ 𝐶𝑖
𝐶0 = 𝐼𝑉
35
2.2.2.b- Cipher Feedback Mode (CFB)

36
2.2.2.b- Cipher Feedback Mode (CFB)

37
Thank You

38

You might also like