You are on page 1of 52

Information Assurance and Security (ITec4143)

Lecture 02: Basic Cryptography

Abey B. (MSc.)

Debre Berhan University


Faculty of Computing
Department of Information Technology

July 29, 2022

Lecture 02 Basic Cryptography July 29, 2022 1 / 52


Outline

Basic cryptographic terms


Symmetric and Public Key Cryptography
Symmetric key cryptography
I Stream vs. block ciphers
I Block cipher modes
I DES
Public key cryptography

Lecture 02 Basic Cryptography July 29, 2022 2 / 52


What is Basic Cryptography

What is Cryptography?
The word Cryptography comes from the Greek words krypto
’hidden’ and grapho ’writing’.
I Therefore, we can say that cryptography is the science of secret, or
hidden writing
Cryptography: is “the science of coding and decoding messages so
as to keep these messages secure”.
Today, many common IT tools use embedded encryption
technologies to protect sensitive information within applications
I All the popular Web browsers use built-in encryption features to enable
secure e-commerce, such as online banking and web shopping

Lecture 02 Basic Cryptography July 29, 2022 3 / 52


Basic Cryptographic Terms

Basic Terminologies
Algorithm: The programmatic steps used to convert a plaintext into
an encrypted sequence of bits that represent the message
Plaintext: The original form of a message
Ciphertext: - The coded/encrypted form of a message
Key: info used in cipher known only by the sender/receiver
I The key which is an input to the algorithm is secret
I Key is a string of numbers or characters
I If same key is used for encryption & decryption the algorithm is
called symmetric
I If different keys are used for encryption & decryption the algorithm
is called asymmetric

Lecture 02 Basic Cryptography July 29, 2022 4 / 52


Basic Cryptographic Terms

Basic Terminologies
Encipher (encrypt): the process of converting plaintext to ciphertext
Decipher (decrypt): recovering plaintext from ciphertext
Cryptography: the study of encryption principles/methods
Cryptanalysis (codebreaking): the study of principles/ methods of
breaking ciphertext without knowing key
Cryptology: the field of both cryptography and cryptoanalysis

Lecture 02 Basic Cryptography July 29, 2022 5 / 52


Classical Symmetric Cryptography

Cipher classification

Lecture 02 Basic Cryptography July 29, 2022 6 / 52


Classical Symmetric Cryptography

Types of classical Ciphers


A cipher is a series of steps in which plaintext is converted in to
cipher text
I Substitution ciphers
F Substitution is each letter of the alphabet is substituted with a
different letter or symbol
F E.g. A becomes E , B becomes E, etc
F Caesar cipher
I Transposition (permutation) ciphers
F The order of the characters in the original message is rearranged
F e.g CIPHER might become REHPIC
I Product Ciphers
F Possibly combine two or more ciphers
F Run plaintext through several iterations of the same encryption
algorithm

Lecture 02 Basic Cryptography July 29, 2022 7 / 52


Classical Symmetric Cryptography

Caesar Cipher
Earliest known substitution cipher
Replaces each letter by 3rd letter on
Example:

What is the plaintext if the ciphertext is: KRZ DUH BRX GRLQJ
With a caesar cipher, there are only 26 possible keys, of which only
25 are of any use
I Since mapping A to A etc doesn’t really obscure the message!

Lecture 02 Basic Cryptography July 29, 2022 8 / 52


Classical Symmetric Cryptography

Example 1
Use the Caesar cipher with shift of 3 to encrypt the message: “We
ride at noon”
Solution
We use the mapping above to replace each letter. W gets replaced
with Z, and so forth, giving the encrypted message: ZH ULGH DW
QRRQ.
Example 2
Decrypt the message GZD KNK YDX MFW JXA if it was encrypted
using a shift cipher with shift of 5.

Lecture 02 Basic Cryptography July 29, 2022 9 / 52


Classical Symmetric Cryptography

Caesar Cipher
Define transformation as:

Mathematically give each letter a number

Then have Caesar cipher as:


C = E(p) = (p + k) mod (26)
p = D(C) = (C – k) mod (26)
This mathematical description uses modulo arithmetic (ie clock
arithmetic)
I When you reach Z you go back to A and start again
I Mod 26 implies that when you reach 26, you use 0 instead (ie the letter
after Z, or 25 + 1 goes to A or 0)
Lecture 02 Basic Cryptography July 29, 2022 10 / 52
Classical Symmetric Cryptography

Monoalphabetic Cipher
Problem is language characteristics
I Human languages are redundant
I Letters are not equally commonly used
English letter frequencies

Note that all human languages have varying letter frequencies,


though the number of letters and their frequencies varies

Lecture 02 Basic Cryptography July 29, 2022 11 / 52


Classical Symmetric Cryptography

Brute Force Attack


A brute force attack is a method for breaking encryption by trying all
possible encryption keys.
To make a brute force attack harder, we could make a more complex
substitution cipher by using something other than a shift of the
alphabet.

Lecture 02 Basic Cryptography July 29, 2022 12 / 52


Classical Symmetric Cryptography

Monoalphabetic Cipher: Cryptanalysis


Given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPF
PESXUDBMETSXAIZVUEPHZHMDZSHZOW
SFPAPPDTSVPQUZWYMXUZUHSXEPYEPO
PDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ
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

Lecture 02 Basic Cryptography July 29, 2022 13 / 52


Classical Symmetric Cryptography

Monoalphabetic Cipher: Cryptanalysis


Letter frequency in cipher text

Lecture 02 Basic Cryptography July 29, 2022 14 / 52


Classical Symmetric Cryptography

Polyalphabetic Cipher
An advanced substitution cipher using two or more alphabets
In polyalphabetic substitutions
I The plaintext of each letter is transformed into its corresponding letters
based on its order of appearance in the plaintext and the sets of
substitution cipher
Note: Each substitution steps use Caesar Cipher substitution
Example:
I Plaintext: ABCDEFGHIJKLMNOPQRSTUVWXYZ
I Substitution cipher 1: DEFGHIJKLMNOPQRSTUVWXYZABC
I Substitution cipher 2: GHIJKLMNOPQRSTUVWXYZABCDEF
I Substitution cipher 3: JKLMNOPQRSTUVWXYZABCDEFGHI
I Substitution cipher 4: MNOPQRSTUVWXYZABCDEFGHIJKL
Find the ciphertext if the plaintext is TEXT?

Lecture 02 Basic Cryptography July 29, 2022 15 / 52


Classical Symmetric Cryptography

Polyalphabetic Cipher
To encode the plaintext TEXT with the given ciphers
1 Substitute the first letter of the plaintext by its corresponding letter
from cipher1; T to W
2 Substitute the second letter of the plaintext by its corresponding letter
from cipher2; E to K
3 Substitute the third letter of the plaintext by its corresponding letter
from cipher3; X to G
4 Substitute the fourth letter of the plaintext by its corresponding letter
from cipher4; T to W
The ciphertext is then WKGF

Lecture 02 Basic Cryptography July 29, 2022 16 / 52


Classical Symmetric Cryptography

Substitution : Vignere Cipher


To encode the plaintext TEXT with the given ciphers
Uses a keyword or phrase in conjunction with a lookuptable (known
as vigenere Tableau) to encrypt a message
Note: keyword and lookuptable is used to encrypt a message
Example
Plaintext message:BIG SECRET
Keyword:Lock

Lecture 02 Basic Cryptography July 29, 2022 17 / 52


Classical Symmetric Cryptography

Substitution : Vignere Cipher


To encode the plaintext TEXT with the given ciphers

Lecture 02 Basic Cryptography July 29, 2022 18 / 52


Classical Symmetric Cryptography

Transposition Cipher
Transposition cipher relies on an algorithm which rearranges the
order of the letters in a plaintext message
In a columnar transposition, a plaintext message is transposed into
several columns
Ciphertext is produced by reading the resulting rows in sequence
Example with 2 columns:
Plaintext: SECRET
Solution
I SE
CR
ET
Ciphertext: SCEERT

Lecture 02 Basic Cryptography July 29, 2022 19 / 52


Classical Symmetric Cryptography

Class Work
1 Plaintext: THIS IS A MESSAGE TO SHOW HOW A
COLUMNAR TRANSPOSITION WORKS.
Key: We arrange the letters in five columns
2 Find the plaintext if the ciphertext is GARNODFENOBYOTOO if
the depth or key is 3

Lecture 02 Basic Cryptography July 29, 2022 20 / 52


Classical Symmetric Cryptography

Solution For Question 1

TSSOHOANIWHAASOLRSTOIMGHWUTPIRSEEOAMROOKIST
WCNASNS
Lecture 02 Basic Cryptography July 29, 2022 21 / 52
Classical Symmetric Cryptography

Transposition Cipher
Plaintext : Geeks for Geeks
Key:HACK
In a transposition cipher, the order of the alphabets is re-arranged to
obtain the cipher-text.
To get Plaintext into Ciphertext follow the following step:

Lecture 02 Basic Cryptography July 29, 2022 22 / 52


Classical Symmetric Cryptography

Encryption
1 The message is written out in rows of a fixed length, and then read
out again column by column, and the columns are chosen in some
scrambled order.
2 Width of the rows and the permutation of the columns are usually
defined by a keyword.
3 For example, the word HACK is of length 4 (so the rows are of length
4), and the permutation is defined by the alphabetical order of the
letters in the keyword. In this case, the order would be “3 1 2 4”.
4 Finally, the message is read off in columns, in the order specified by
the keyword.

Lecture 02 Basic Cryptography July 29, 2022 23 / 52


Classical Symmetric Cryptography

Transposition Cipher
Example:
I Plain text: Attack Postponed Until Two AM
I Key: 3 4 2 1 5 6 7 7x4

To encrypt, start with the column that is labeled 1, in this case


column 4
Write down all the letters in that column
Proceed to column 3, which is labeled 2, then column 1, then
column 2, then columns 5, 6, and 7
Ciphertext: APTMTTTNAAODWTSUOCOIKNLPET
Find the plaintext if the ciphertext is
EAEORNNOHMDRIEUNEYTMASSYRTIZ
Lecture 02 Basic Cryptography July 29, 2022 24 / 52
Classical Symmetric Cryptography

Rail-Fece Transposition
In rail-fence transposition,is plaintext is written down as sequence
of diagonals and then read off as sequence of row.
Example
For example, to encipher the message “MEET ME AFTER THE
GOOD PARTY” with a rail fence of depth 3 (number of rows,
which is the key), we write the following

The ciphertext become: MMTHORETEFETEODATEARGPY

Lecture 02 Basic Cryptography July 29, 2022 25 / 52


Class Work
Encipher the message ”neso academy is the best”with rail fence of
depth 2

Lecture 02 Basic Cryptography July 29, 2022 26 / 52


1 Home Work
2 Encipher the message ”Thank you very much ”with rail fence of
depth 3
3 what is the plaintext of the following ciphertext:
MMTHORETEFETEODATEARGPY

Lecture 02 Basic Cryptography July 29, 2022 27 / 52


Classical Symmetric Cryptography

Block Vs. Stream Ciphers


Encryption could be conducted in to either stream or block forms

Lecture 02 Basic Cryptography July 29, 2022 28 / 52


Classical Symmetric Cryptography

Stream Ciphers
Stream ciphers commonly work as follows:
I Encrypt data one bit or one byte at a time
I A single character of plaintext is combined with a single character from
a key stream to produce a single character of ciphertext
I The ciphertext character from step 1 is sent to the receiver
I Steps 1 and 2 are repeated until the entire message has been sent
I Examples of Stream Ciphers
1 Salsa20 (software and hardware implementations),
2 ChaCha20 (the modified version of Salsa20)
3 RC4 (for wireless networks)
4 A5 (for GSM cellular networks)

Lecture 02 Basic Cryptography July 29, 2022 29 / 52


Classical Symmetric Cryptography

Block ciphers
In block cipher, a group of plaintext characters of a fixed size (a
block) is encrypted at once and sent to the receiver
I The process is repeated until the entire plaintext message has been sent
The number of bits in block is fixed
Examples of Block Ciphers:
1 Data Encryption Standard (DES)
2 Triple DES (3DES or TDEA)
3 Advanced Encryption Standard (AES)
4 International Data Encryption Algorithm (IDEA)

Lecture 02 Basic Cryptography July 29, 2022 30 / 52


Classical Symmetric Cryptography

Block Vs. Stream Ciphers

Lecture 02 Basic Cryptography July 29, 2022 31 / 52


Classical Symmetric Cryptography

Challenge of Symmetric Key Cryptosystem


There are two restrictive challenges of employing symmetric key
cryptography.
1 Key establishment: Before any communication, both the sender
and the receiver need to agree on a secret symmetric key.
It requires a secure key establishment mechanism in place.
2 Trust Issue : Since the sender and the receiver use the same
symmetric key, there is an implicit requirement that the sender
and the receiver ‘trust’ each other.
3 large number of keys are needed for large number of users to securely
communicate.
F separate key is needed for each communicating sender/receiver
F For n communicating users, we would thus need: n*(n-1)/2 keys
F Each user should store n-1 keys

Lecture 02 Basic Cryptography July 29, 2022 32 / 52


Asymmetric cryptosystems

Also called Public key encryption(PKE)


Uses a pair of keys for encryption and decryption
1 Public key for Encryption/Decryption
2 Private key for Decryption/Encryption
Messages encoded using public key can only be decoded by the
private key
I Secret transmission of key for decryption is not required
I Every entity can generate a key pair and they release only one key’s
either public key or private key
I keys for encryption and decryption are different but form a unique pair

Lecture 02 Basic Cryptography July 29, 2022 33 / 52


Public Key Cryptography

Given:
I Everybody knows Bob’s public key
I Only Bob knows the corresponding private key
Goals:
I Alice wants to send a message that only Bob can read
I Bob wants to send a message that only Bob could have written
Applications:
I Encryption for confidentiality
F Anyone can encrypt a message
F With symmetric crypto, must know the secret key to encrypt
I Only someone who knows the private key can decrypt
F Secret keys are only stored in one place

Lecture 02 Basic Cryptography July 29, 2022 34 / 52


Public Key Cryptography

Lecture 02 Basic Cryptography July 29, 2022 35 / 52


Asymmetric cryptosystems

Requirements

Lecture 02 Basic Cryptography July 29, 2022 36 / 52


Asymmetric cryptosystems

Asymmetric key encryption algorithms


Two most popular algorithms are:
1 RSA
2 El Gamal

Lecture 02 Basic Cryptography July 29, 2022 37 / 52


Asymmetric cryptosystems

Asymmetric key encryption algorithms


RSA

Lecture 02 Basic Cryptography July 29, 2022 38 / 52


Asymmetric cryptosystems

RSA
Developed by Ron Rivest, Adi Shamir, Len Adelman
Most popular public key algorithm
Variable Key Size (512, 1024, or 2048 bits)

Lecture 02 Basic Cryptography July 29, 2022 39 / 52


Asymmetric cryptosystems

RSA need the following steps


1 Choose two large prime numbers p & q
2 Compute n=pq and z=(p-1)(q-1)
3 Choose number e, less than n, which has no common factor (other
than 1) with z
4 Find number d, such that ed – 1 is exactly divisible by z
5 Keys are generated using n, d, e
I Public key is (n,e)
I Private key is (n, d)
6 Encryption: c = me mod n
I m is plain text
I c is cipher text
7 Decryption: m = cd mod n

Lecture 02 Basic Cryptography July 29, 2022 40 / 52


Asymmetric cryptosystems

RSA Example 1
Encrypt the word love using RSA Algorithm
Solution
1 P=5 & q=7
2 n=5*7=35 and z=(4)*(6) = 24
3 e=5
4 d = 29 , (29x5 –1) is exactly divisible by 24
5 Keys generated are
F Public key: (35,5)
F Private key is (35, 29)

F The cipher text of love became:qovj

Lecture 02 Basic Cryptography July 29, 2022 41 / 52


Asymmetric cryptosystems

RSA Example 1
Decrypt the word qovj using (m = cd mod n)
n = 35, d=29

Lecture 02 Basic Cryptography July 29, 2022 42 / 52


Asymmetric cryptosystems

RSA Example 2
Encrypt plaintext 9 using the RSA public-key encryption algorithm.
Uses prime numbers 7 and 11 to generate the public and private keys.

Lecture 02 Basic Cryptography July 29, 2022 43 / 52


Asymmetric cryptosystems

Home WORK
In an RSA cryptosystem, a particular A uses two prime numbers, 13
and 17, to generate the public and private keys. If the public of A is
35. Then the private key of A is . . . . . . . . . . . . . . . ?

Lecture 02 Basic Cryptography July 29, 2022 44 / 52


Asymmetric Encryption Weaknesses

1 Efficiency is lower than Symmetric Algorithms


I Symmetric encryption systems are typically at least 10,000 times
faster than PKEs
I PKE algorithms uses Slow exponentiation and rely upon
computationally expensive multiplication and division operation
I SKE uses extremely fast bit operation such as bit-wise addition
2 Probable for man-in-the middle attack

Lecture 02 Basic Cryptography July 29, 2022 45 / 52


Asymmetric Encryption

Used to improve efficiency


1 Symmetric key is used for encrypting data
2 Asymmetric key is used for encrypting the symmetric key

Lecture 02 Basic Cryptography July 29, 2022 46 / 52


Digital Signatures

What is Digital Signatures?


A digital signature is a mechanism that allows the creator of a
message to attach a code that acts as a signature.
The signature is derived from the original message by taking the hash
of the message and encrypting the message with the creator’s private
key.
Digital Signatures are numbers

Lecture 02 Basic Cryptography July 29, 2022 47 / 52


Hash functions

What is Hash functions?


A hash function H takes a variable-size message m as input and
produces a fixed-size output, referred to as hash code or message
digest or hash value H (m)

Lecture 02 Basic Cryptography July 29, 2022 48 / 52


Digital Signatures

Examples of digital signature


1 I agree
efcc61c1c03db8d8ea8569545c073c814a0ed755
2 I am an Engineer
ea0ae29b3b2c20fc018aaca45c3746a057b893e7
3 I am a Engineer
01f1d8abd9c2e6130870842055d97d315dff1ea3

Lecture 02 Basic Cryptography July 29, 2022 49 / 52


Digital Signatures

A digital signature has two goals


1 A guarantee of the source of the data
2 Proof that the data has not been damaged
Digital signature protects against Man in the middle attack

Lecture 02 Basic Cryptography July 29, 2022 50 / 52


Digital Signatures

Hana went to send message to Ahmed using digital signature

Lecture 02 Basic Cryptography July 29, 2022 51 / 52


End Chapter Two

Question
Many Thanks!

Lecture 02 Basic Cryptography July 29, 2022 52 / 52

You might also like