0% found this document useful (0 votes)
89 views29 pages

CSCI3310 Lecture 03

This document discusses cryptography and different types of encryption ciphers. It begins with an introduction to cryptography and the goals of secure communication. It then describes private key cryptography where the sender and receiver share a secret key, and public key cryptography where different keys are used for encryption and decryption. The document proceeds to provide examples of the Caesar cipher and affine cipher encryption methods. It gives examples of encrypting and decrypting messages using shift ciphers and the affine cipher. It also discusses cryptanalysis techniques for analyzing encrypted messages without knowing the encryption key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views29 pages

CSCI3310 Lecture 03

This document discusses cryptography and different types of encryption ciphers. It begins with an introduction to cryptography and the goals of secure communication. It then describes private key cryptography where the sender and receiver share a secret key, and public key cryptography where different keys are used for encryption and decryption. The document proceeds to provide examples of the Caesar cipher and affine cipher encryption methods. It gives examples of encrypting and decrypting messages using shift ciphers and the affine cipher. It also discusses cryptanalysis techniques for analyzing encrypted messages without knowing the encryption key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

CSCI 3310: Mathematical Computation

Cryptography

Bishr Mamoun Iquelan

Associate Professor
Department of Mathematics,
Islamic University of Gaza

2022-2023, Semester 1
Cryptography

► Cryptography is the study of techniques for secure


transmission of information in the presence of
adversaries

► How can Alice send secrete messages to Bob without


Eve being able to read them?

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 1 / 27


Private vs. Public Crypto Systems

► Two different kinds of cryptography systems:


1 Private (secret) key cryptography

2 Public key cryptography

► In private key cryptography, sender and receiver


agree on secret key that both use to
encrypt/decrypt the message.

► In public key cryptography, a public key is used


to encrypt the message, and private key is used
to decrypt the message.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 2 / 27


Private Key Cryptography
One of the earliest known cryptographic ciphers was used by Julius
Caesar. His strategy was to shift each letter of the alphabet forward
3 places, wrapping around when you get to the end. In this scheme,
for example: A −→ D, K −→ N, Y −→ B
This is often called a Caesar Cipher or a Shift Cipher.
► Mathematically, we can accomplish this by assigning to
each letter a number between 0 and 25. For example:
A −→ 0, K −→ 10, Y −→ 24
► The encoding can be done by passing the value through a
shift function modulo 26:
f (p) = (p + 3) mod 26.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 3 / 27


Generalization the Caesar cipher

► In general, for a shift k we can use the function


f (p) = (p + k) mod
26 We can encode (encrypt) a message
by:
1 Convert letters to numbers between 0
and 25,
2 Pass each value through f (p).
► Both receiver and sender need to know k to encrypt/decrypt.
The integer k is called a key.
► Analogy: Alice wants to send Bob briefcase with secret
message; they have a common key to lock/unlock
briefcase
► Alice locks briefcase with shared key and Bob unlocks brief
case with shared key
Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 4 / 27
Cryptography warm-up

Example 1:
Encrypt the message “MEET YOU IN THE PARK” using shift
cipher with k = 3.
Solution:
1 Convert to numbers:

12 4 4 19 24 14 20 8 13 19 7 4 15 0
17 10,

2 Shift: (replace each of these numbers) p by


f (p) = (p + 3) mod 26,

15 7 7 22 1 17 23 11 16 22 18 3 20
10 7 13,
3 Translating the numbers back to letters produces the encrypted
message “PHHW BRX LQ WKH SDUN”.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 5 / 27


Cryptography warm-up

► How do we decode a message like


“PHHW BRX LQ WKH SDUN”?

► If we know the shift, then it’s easy - just run the message
through the inverse:

f − 1
(p) = (p − k) mod 26

So, each letter in the coded message is shifted back k


letters in the alphabet, with the first k letters sent to the
last k letters. This process of recovering the original
message from the encrypted message is called decryption.

► Why is this not a very secure cipher?

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 6 / 27


Cryptography warm-up

Example 2:
Encrypt the message “STOP GLOBAL WARMING” using the shift
cipher with k = 11.
Solution:
1 Replace each letter with the corresponding element of Z26.

18 19 14 15 6 11 14 1 0 11 22 0 17 12 8 13 6.

2 Apply the shift f (p) = (p + 11) mod 26, yielding

3 4 25 0 17 22 25 12 11 22 7 11 2 23 19 24 17.

3 Translating the numbers back to letters produces the ciphertext

“DEZA RWZMLW HLCXTYR”.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 7 / 27


Cryptography warm-up
Example 3:
Decrypt the message “LEWLYPLUJL PZ H NYLHA ALHJOLY” that
was encrypted using the shift cipher with k = 7.
Solution:
1 Replace each letter with the corresponding element of Z26.

11 4 22 11 24 15 11 20 9 11 15 25 7 13 24 11 7 0 0 11 7
9 14 11 24.

2 Shift each of the numbers by −k = −7 mod 26, yielding


4 23 15 4 17 8 4 13 2 4 8 18 0 6 17 4 0 19 19 4 0
2 7 4 17.

3 Translating the numbers back to letters produces the decrypted


message

“EXPERIENCE IS A GREAT TEACHER”.


Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 8 / 27
The Affine Cipher
► Instead of only shifting, multiply and then shift
f (p) = (ap + b) mod 26
where a and b are integers with gcd(a, 26) =
1.
► Suppose we know a and b (i.e., we have the key) -
how could we decode a message?
➣ Suppose we have an encrypted character c that we
know must satisfy
c ≡ ap + b mod 26
➣ Then we need to solve this congruence for p. So
subtract b from both sides
c − b ≡ ap mod 26
➣ Now we need the inverse of a (modulo 26), which we
and we
know exists because
p ≡gcd(a,
a¯(c −26)
b) = 1. Call the inverse
mod
have
a¯,
Dr. Bishr M. Iquelan (IUGaza)
26
4.6-Cryptography 9 / 27
1st Semester, 2022-2023
The Affine Cipher

Example 4:
What letter replaces the letter K when the function

f (p) = (7p + 13) mod 26

is used for encryption? In other words, use an affine


cipher
with a = 7 and b = 13 to encrypt the letter K .
Solution:
The numerical value for K is 10, so we have

a × 10 + b = 7 × 10 + 13 = 83 ≡ 5 mod 26,

which is then replaced by F .

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 10 / 27


The Affine Cipher
Example 5:
Find a decryption formula for this affine cipher and use it to decrypt the
character F.
Solution:
We need the inverse of a = 7 modulo 26:
26 = 3.7 + 5 1=5− 2× 2
7 = 1.5 + 2 = 5 − 2 × (7 − 1 × 5)
5 = 2.2 + 1 =3× 5− 2× 7
Using back substitution, we have = 3 × (26 − 3 × 7) − 2 ×
7
= 3 × 26 − 11 × 7
So the inverse of 7 modulo 26 is a¯ = − 11.
Plugging into the decryption formula we have: (with character F ›→
5)
p ≡ (c − b) mod 26
≡ − 11 × (5 − 13) mod 26
≡ 88 mod 26 (note:26 × 3 =
78)
Dr. Bishr M. Iquelan (IUGaza) ≡ 10 mod 26 ›→ K
4.6-Cryptography 1st Semester, 2022-2023 11 / 27
Cryptanalysis of Affine Ciphers

► The process of recovering plaintext from ciphertext without


knowledge both of the encryption method and the key is known
as cryptanalysis or breaking codes.
► An important tool for cryptanalyzing ciphertext produced with a
affine ciphers is the relative frequencies of letters. The nine most
common letters in the English texts are:
E 13%, T 9%, A 8%, O 8%, I 7%, N 7%, S 7%, H 6%, and R
6%.
► To analyze ciphertext:
➣ Find the frequency of the letters in the ciphertext.
➣ Hypothesize that the most frequent letter is produced by
encrypting E.
➣ If the value of the shift from E to the most frequent letter is
K, shift the ciphertext by − K and see if it makes sense.
➣ If not, try T as a hypothesis and continue.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 12 / 27


Cryptanalysis

Example 6:
We intercepted the message

“ZNK KGXRE HOXJ MKZY ZNK CUXS”

that we know was produced by a shift cipher. Let’s


try to cryptanalyze.
Solution:
The most common letter in the ciphertext is K. So
perhaps the letters were shifted by 6 since this would
then map E to K. Shifting the entire message by −6
gives us

“THE EARLY BIRD GETS THE WORM.”

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 13 / 27


Cryptosystems

Definition:

A cryptosystem is a five-tuple (P , C, K, E, D), where


► P is the set of plainntext strings,
► C is the set of ciphertext strings,
► K is the keyspace (set of all possible keys),
► E is the set of encryption functions, and
► D is the set of decryption functions.

The encryption function in E corresponding to the key k is


denoted by Ek and the decryption function in D that decrypts
ciphertext encrypted using Ek is denoted by Dk . Therefore:

Dk (Ek (p)) = p, for all plaintext strings


p.
Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 14 / 27
Cryptosystems

Example 7:
Describe the family of shift ciphers as a
cryptosystem. Solution:
Assume the messages are strings consisting of
elements in
Z26.
► P is the set of strings of elements in Z26,
► C is the set of strings of elements in Z26,
► K = Z26,
► E consists of functions of the form

Ek (p) = (p + k) mod 26, and

► D is the same as E where Dk (p) = (p − k) mod


26.
Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography st 15 / 27
1 Semester, 2022-2023
Public Key Cryptography

► All classical ciphers, including shift and affine ciphers, are


private key cryptosystems. Knowing the encryption key
allows one to quickly determine the decryption key.

► All parties who wish to communicate using a private key


cryptosystem must share the key and keep it a secret.

► In public key cryptosystems, first invented in the 1970s,


knowing how to encrypt a message does not help one to
decrypt the message. Therefore, everyone can have a
publicly known encryption key. The only key that needs to
be kept secret is the decryption key.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 16 / 27


Public Key Cryptography

➣ Bob has two keys: public and


private

➣ Everyone knows Bob’s public key,


but only he knows his private key

➣ Alice encrypts message using


Bob’s public key

➣ Bob decrypts message using


private key

➣ Public key can encrypt, but not


decrypt

➣ Therefore, no one can read


message accept Bob

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 17 / 27


Public Key Cryptography Overview

► This double lock example illustrates how parties can


securely transmit information without exchanging
secret keys

► Many modern cryptosystems work roughly this way

► Most commonly used public key system is RSA

► Great application of number theory and things we


have learned

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 18 / 27


RSA History

► A public key cryptosystem, now known as the RSA


system was introduced in 1976 by three researchers
Rivest, Shamir, and Adlemann, at MIT.

► It is now known that the method was discovered


earlier by Clifford Cocks, working secretly for the UK
government, but classified – unknown until 90’s.

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 19 / 27


RSA Cryptosystem

High Level Math Behind RSA

► Choose two distinct prime numbers p and q

► Let n = p.q and k = (p − 1)(q − 1)

► Choose integer e where 1 < e < k


and gcd(e, k) = 1

► (n, e) is released as the public key

► Let d be the multiplicative inverse of


e modulo k,
so d.e ≡ 1 mod k

► (n, d ) is kept secret as the private


key
Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 20 / 27
Encryption in RSA

► To send message to Bob, Alice first represents message


as a sequence of numbers

► Call this number representing message M

► Alice then uses Bob’s public key (n, e) to


perform encryption as:
C ≡ M e mod n

► C is called the ciphertext

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 21 / 27


RSA Decryption

► How do we decrypt ciphertext using private keys p, q?


► Decryption key d is the inverse of e modulo
k = (p − 1)(q − 1)
d.e ≡ 1 mod k
► However, since adversaries do not know p, q, they
cannot compute d with reasonable computational effort!
► Using the Chinese remainder theorem and another theorem
called Fermat’s Little Theorem, it can be shown that:
(M e )d ≡ M mod n
► Since the ciphertext C is just M e , Cd mod n
allows decrypting the message
► Since Bob can compute d using p, q, Bob can easily
decrypt message, but no one else can!

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 22 / 27


The RSA Encryption Algorithm

Example 8:
Suppose Alice wants her friends to encrypt email messages before sending them
to her. Computers represent text as long numbers (01 for ”A”, 02 for ”B” and
so on), so an email message is just a very big number. The RSA Encryption
Scheme is often used to encrypt and then decrypt electronic communications.
General Example
Alice’s Setup: Alice’s Setup:
► Chooses ► p = 11
p, q. and q =
► Calculate k = (p − 1)(q −
► Calculates 3.
s1)n = ► n = pq
► Chooses numbers e and d so
pq. = 11.3
that e.d has a remainder of 1
= 33.
when divided by k.
► k = 10.2
► Publishes her public key (n,
= 20.
e).
► If e = 3 and d = 7, then ed =
21 has a remainder of 1 when
Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 23 / 27
The RSA Encryption Algorithm

Example 8 Cont.:
Bob encrypts M for Alice: Bob encrypts message M = 14:
► Finds Alice’s public key (n, e). ► (n, e) = (33, 3).
► Finds the remainder C when M e ► When 143 = 2744 is divided by
is divided by n. 33, the remainder is C = 5.
► Sends ciphertext C to Alice. ► Sends ciphertext C = 5 to
Alice.
Alice receives & decrypts C:
► Uses her private key (n, d ). Alice decrypts ciphertext C = 5:
► (n, d ) = (33, 7).
► Finds remainder R when Cd is
divided by n. ► When 57 = 78125 is divided by
33, the remainder is R = 14.
► R matches the message M
that wanted to send to Alice!
Bob ► message
R = 14 =from
M, Bob!
the original

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 24 / 27


Encryption Example

Example 9:
► Encrypt message ”STOP” using RSA with n = 2537, e = 13

► First convert each letter to a number in Z26 = [0, 25] :


S = 18, T = 19, O = 14, P = 15

► Group sequence into blocks of 4 digits:

M = 1819 1415

► Now encrypt each block as C = M 13 mod 2537


► For first block, 181913 mod 2537 = 2081, for second block
141513 mod 2537 = 2182
► Ciphertext: 2081 2182

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 25 /


Decryption Example

Example 10:
► Decrypt the cipher text 0981 0461 for the RSA cipher with
p = 43, q = 59, and e = 13.
► First we need to compute d, the inverse of e modulo
k = (p − 1)(q − 1)
► Here, k = (p − 1)(q − 1) = 2436, and to find d = e¯
solve:
13x ≡ 1 mod 2436
► To solve this, first compute s, t such that:
► Apply extended Euclidian13s + 2436t s==1 937, t = −5.
algorithm:
Thus
d = e¯ = 937
► 0981937 mod 2537 = 0704, 04619937 mod 2537 = 1115
► Thus, decrypted message is 0704 1115, or in English, ”HELP”

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 26 / 27


Security of RSA

► The encryption function used in RSA is a trapdoor


function
► Trapdoor function is easy to compute in one direction, but
very difficult in reverse direction without additional
knowledge
► Encryption direction is easy because just requires
exponentiation and mod
► Decryption without private key is very hard because
requires prime factorization
► Therefore, security of RSA depends on difficulty of prime
factorization

Dr. Bishr M. Iquelan (IUGaza) 4.6-Cryptography 1st Semester, 2022-2023 27 / 27


End of lecture 3.
Thank you.!!!

You might also like