0% found this document useful (0 votes)
3 views

03 CS285 Number Theory and Cryptography Chap4 Updated

Chapter 4 covers key concepts in number theory and cryptography, including divisibility, prime numbers, greatest common divisors, and modular arithmetic. It also discusses classical and public key cryptography, particularly the RSA cryptosystem, emphasizing the importance of encryption methods for secure communication. The chapter provides examples of various encryption techniques, such as the Caesar cipher and shift ciphers, along with their decryption processes.

Uploaded by

owacc77777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

03 CS285 Number Theory and Cryptography Chap4 Updated

Chapter 4 covers key concepts in number theory and cryptography, including divisibility, prime numbers, greatest common divisors, and modular arithmetic. It also discusses classical and public key cryptography, particularly the RSA cryptosystem, emphasizing the importance of encryption methods for secure communication. The chapter provides examples of various encryption techniques, such as the Caesar cipher and shift ciphers, along with their decryption processes.

Uploaded by

owacc77777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Number Theory and

Cryptography
CHA PT ER 4

S EC T ION 4 . 1 , 4 . 3 , 4 . 6
4.1 Divisibility and Modular Arithmetic
4.3 Primes and Greatest Common Divisor
4.6 Cryptography
The Integers & Division

divide_

n
n

intafford
Divisors Examples

11 774 7
false
14 1 17 True

24 1 24 True
false

24 0 0 True

4
Divisors Examples

5
Facts: The Divides Relation
1131213 18 3 1218

3121 3 18 73 30

26 726.8
2624248
48 816
Composite & Prime Numbers
9itself
49
Fundamental Theorem of Arithmetic

15522.1
2

Theorem how to find


with the hum Prime or composite
1 Faq 7
that
2
finishing
3 519in
ng compsit
decimal

ifL
Prime Factorization Technique any
int
important

2 n

3 n 10
5 n
Prime Factorization Examples
Exercise 1: Show that 100 is composite?

I
me
If a
to
IEEE a

Exercise 2: Show that 101 is prime?


am

yesits a prime num y


Exercise 3: Find the prime factors of 7007?

E
217007 317007
E.gg kid I E in 7007721

7 7007 507007 is a

11
12
Primary Testing Example

13
Greatest Common Division (GCD)

2int

14
2 Ways to find GCD

method 1
metritis number
I fi i
36 2
36 22
3

god 24136

16
2
120
60 2
so 2 23 5 3
15 5
3 3 august
smog
l l l

go 2 50
2 533

17
420 2 98 2
Greatest Common Division
I

24

Did 2 7 14

30

18
17 17
I l

ged 17,22 1

E
F
we have 1
Gt 1 is not 19
Prime number
Greatest Common Division
Relatively Prime

gcdcn tt ll

gd33.71

¾ ¾ sina
sn 223 12

¾ gcd 2425
atively
Prime
20
Greatest Common Division
Relatively Prime

21
Least Common Multiple
100k the biggest c f
p
Eg
6k
we look
math
c

23
Division
The Division
“Algorithm”
Examples
Solutions
mod Function Start Here

4
find reminder

9
17
U

6
28
ive
mod Function
Question
·What time it will be (on a 24-hour clock) 50 hours from 11 am?

·After 24 hours it will be 11 am


·After another 24 hours it will be 11 am
◦ This is after 48 hours
·After 2 more hours it will be 13 (1 pm)!
◦ This is after 50 hours

·Is there another way?


Question
·What time it will be (on a 24-hour clock) 50 hours from 11 am?
antie

0 EE
· Calculate (11 + 50) mod 24?

·We can also use mod Function to convert time from 24-hour clock to 12-hour
clock

·Calculate 13 mod 12?


·Calculate 23 mod 12?
Modular Congruence

modems

i
20
Examples
crf or Q 17 5most
17mod615mod6
6 55
5
6 17 5 6 12 2
24 14 mod 6
yes they're congruent

24mod6 14mod6
6 FI or
no
Te Titstop
here
Useful Congruence Theorems
Ex.:

0
farity
4.6 Cryptography
Td g
Section Summary
Classical Cryptography
Cryptosystems
Public Key Cryptography
RSA Cryptosystem
Cryptographic Protocols
Primitive Roots and Discrete Logarithms
Why Cryptography
Cryptography is a science that applies complex mathematics and
logic to design strong encryption methods.
Cryptography is also an art.
Cryptography allows people to keep confidence in the electronic
world.
People can do their business on electric channel without worrying of
deceit and deception.
Symmetric Encryption (single-key encryption)
Symmetric Encryption
The universal technique for providing confidentiality
also referred to as single-key encryption
Algorithms: DES, Triple DES, and AES

we_
Two requirements for secure use:
◦ need a strong encryption algorithm
◦ sender and receiver must have obtained copies of the secret key
in a secure fashion
◦ and must keep the key secure
Symmetric Encryption

TEiii.tn

HEI
F.e
en.pe woot
city equation
t.tt
Caesar Cipher
 Julius Caesar created secret messages by shifting each letter three letters
forward in the alphabet (sending the last three letters to the first three
letters.)
AIDEF
 For example, the letter B is replaced by E and the letter X is replaced by A.
This process of making a message secret is an example of encryption.
Here is how the encryption process works:
◦ Replace each letter by an integer from Z26, that is an integer from 0 to 25
representing one less than its position in the alphabet.
t.net
is
◦ The encryption function is f(p) = (p + 3) mod 26. It replaces each integer p in
the set {0,1,2,…,25} by f(p) in the set {0,1,2,…,25} .
AB PE
◦ Replace each integer p by the letter with the position p + 1 in the alphabet.
Caesar cipher
Caesar Cipher
etm
orExample: Encrypt the message “MEET YOU IN THE PARK” using the Caesar cipher.
Solution: 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f(p) = (p + 3) mod 26.
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13.
Translating the numbers back to letters produces the encrypted message
“PHHW BRX LQ WKH SDUN.”
f 12 26 19
12 3 mod26 15mod

Ei
zu 24 3 mod26 27mod26
in 14 3 mod 26 17mod 26 17
26 23
SC

Caesar Cipher
To recover the original message, use f−1(p) = (p−3) mod 26. So, each
letter in the coded message is shifted back three letters in the
alphabet, with the first three letters sent to the last three letters. This
process of recovering the original message from the encrypted
message is called decryption.
The Caesar cipher is one of a family of ciphers called shift ciphers. Letters
can be shifted by an integer k, with 3 being just one possibility. The
encryption function is
f(p) = (p + k) mod 26
and the decryption function is
f−1(p) = (p−k) mod 26
The integer k is called a key.
Shift Cipher 018,45 s
Example 1: Encrypt the message “STOP GLOBAL WARMING” using the shift cipher with
k = 11.
apply encrption function f p et k mod26 11mod26

iieiiiiiiiii.is
DEZA
Shift Cipher
Example 1: Encrypt the message “STOP GLOBAL WARMING” using the shift cipher with
k = 11.
Solution: 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.
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.
Translating the numbers back to letters produces the ciphertext
“DEZA RWZMLW HLCXTYR.”
Shift Cipher
Example 2: Decrypt the message “LEWLYPLUJL PZ H NYLHA ALHJOLY” that was
encrypted using the shift cipher with k = 7.
Shift Cipher cypher text if
Example 2: Decrypt the message “LEWLYPLUJL PZ H NYLHA ALHJOLY” that was
encrypted using the shift cipher with k = 7.
Solution: 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.
Shift each of the numbers by −k = −7 modulo 26, yielding f p p 7 mod 26
0 Eretria
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.
Translating the numbers back to letters produces the decrypted message
4g “EXPERIENCE IS A GREAT TEACHER.”

I iiii iii iiiiii iiif a 11 7 mod26 u


Affine Ciphers
Shift ciphers are a special case of affine ciphers which use functions of the form
f(p) = (ap + b) mod 26,
where a and b are integers, chosen so that f is a bijection.
The function is a bijection if and only if gcd(a,26) = 1.
Example: What letter replaces the letter K when the function f(p) = (7p + 3) mod 26 is
used for encryption. Eigastletter co 7110 3 mod26 7,3 26
Solution: Since 10 represents K, f(10) = (7∙10 + 3) mod 26 =21, which is then
replaced by V.
To decrypt a message encrypted by a shift cipher, the congruence c ≡ ap + b (mod 26)
needs to be solved for p.
◦ Subtract b from both sides to obtain c− b ≡ ap (mod 26).
◦ Multiply both sides by the inverse of a modulo 26, which exists since gcd(a,26) = 1.
◦ ā(c− b) ≡ āap (mod 26), which simplifies to ā(c− b) ≡ p (mod 26).
◦ p ≡ ā(c− b) (mod 26) is used to determine p in Z26.
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:

mymoiiii
◦ 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.

x.im
◦ If not, try T as a hypothesis and continue.
Example: We intercepted the message “ZNK KGXRE HOXJ MKZY ZNK CUXS” that we know was
produced by a shift cipher. Let’s try to cryptanalyze.
ii onsia
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.”
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 cipher text encrypted using Ek is denoted
by Dk. Therefore:
Dk(Ek(p)) = p, for all plaintext strings p.
Cryptosystems
Example: 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 .
Public Key Cryptography
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.
Clifford Cocks
The RSA Cryptosystem (Born 1950)

A public key cryptosystem, now known as the RSA system was introduced in
1976 by three researchers at MIT.

Leonard
Ronald Rivest Adi Shamir Adelman
(Born 1948) (Born 1952) (Born 1945)

It is now known that the method was discovered earlier by Clifford Cocks,
working secretly for the UK government.
The RSA Cryptosystem
The RSA algorithm involves four steps: key generation, key distribution,
encryption and decryption.
penigtion irivener
The public encryption key is (n,e), where n = pq, the modulus is the product of
re each,
two large primes p and q ,say with 200 digits s s crossinum
and an exponent e that is
relatively prime to (p−1)(q −1).
The two large primes can be quickly found using probabilistic primarily
tests, discussed earlier.
But n = pq, with approximately 400 digits, cannot be factored in a reasonable
length of time.
P x q
The RSA Cryptosystem
Step-1: Select two prime numbers p and q where p ≠ q.
7
Step-2: Calculate n = p * q. shouting
Step-3: Calculate Ф(n) = (p-1) * (q-1).
sina.se
pox
Step
-4: Select e such that, e is relatively prime to Ф(n), i.e. (e, Ф(n)) = 1 and 1 < e < Ф(n) e 2 ged e 12
accrupt
Step-5: Calculate d = e -1 mod Ф(n) or ed = 1 mod Ф(n).
Step-6: Public key = {e, n}, private key = {d, n}.
Step-7: Find out cipher text using the formula,
cighent pl.in
C = Pe mod n where, P < n where C = Cipher text, P = Plain text, e = Encryption key and n=block size.
Step-8: P = Cd mod n. Plain text P can be obtain using the given formula. where, d =decryption key
RSA algorithm explanation -step by step example
Step – 1: Select two prime numbers p and q where p ≠ q.
Example, Two prime numbers p = 13, q = 11.

Step – 2: Calculate n = p * q.
Example, n = p * q = 13 * 11 = 143.

Step – 3: Calculate Ф(n) = (p-1) * (q-1).


Example, Ф(n) = (13 – 1) * (11 – 1) = 12 * 10 = 120.

Step – 4: Select e such that,


120 1
1- coprime with n and Ф(n), i.e. (e, Ф(n)) = 1 and e 1m 1 ged e
Effigg
2- 1 < e < Ф(n). sed 7,120 1
Example, Select e = 13, gcd (13, 120) = 1. ocd 11 120
sad 13,120
1
1
fIof
Tiniest
Continue…
Step – 5: Calculate d = e -1 mod Ф(n) or e * d = 1 mod Ф(n)
Example, Finding d: e * d mod Ф(n) = 1
13 * d mod 120 = 1
formula
(How to find: d *e = 1 mod Ф(n)  d = ((Ф(n) * i) + 1) / e
decimal num
d = (120 + 1) / 13 = 9.30 (∵ i = 1) has to be integernot
d = (240 + 1) / 13 = 18.53 (∵ i = 2)
it
d = (360 + 1) / 13 = 27.76 (∵ i = 3)
d = (480 + 1) / 13 = 37 (∵ i = 4)) I
sto
Continue…
Step – 6: Public key = {e, n}, private key = {d, n}.
Example, Public key = {13, 143} and private key = {37, 143}.
Step – 7: Find out cipher text C using the formula, C = Pe mod n where, P < n.
Encryption Example, Plain text P = 13. (Where, P < n)
C = Pe mod n = 1313 mod 143 = 52.
Step – 8: P = Cd mod n. Plain text P can be obtain using the given formula.
Decryption Example, Cipher text C = 52
P = Cd mod n = 5237 mod 143 = 13.

66
Example
Encrypt (C = Pe
12
mod n ) the message B using the RSA cryptosystem with key
e n
(5,14):
c phoan25 mod14= 32 mod 14 = 4 D
4D
Decrypt (P = Cd mod n ) the cipher text D using the RSA cryptosystem with key
d n
(11,14): p c mod n
411 mod 14 =4194304 mod 14 ≈2
2 B
RSA Encryption
To encrypt a message using RSA using a key (n,e) :
1. Translate the plaintext message M into sequences of two digit integers
representing the letters. Use 00 for A, 01 for B, … 25 for Z.
2. Concatenate the two digit integers into strings of digits.
3. Divide this string into equally sized blocks of 2N digits (N = number of
letters in the block) where 2N is the largest even number 2525…25 with
2N digits that does not exceed n.
4. The plaintext message M is now a sequence of integers m1,m2,…,mk.
5. Each block (an integer) is encrypted using the function C = Me mod n.
RSA Encryption- example
Example: Encrypt the message STOP using the RSA cryptosystem with key(2537,13).
◦ 2537 = 43∙ 59,
◦ p = 43 and q = 59 are primes and gcd(e,(p−1)(q −1)) = gcd(13, 42∙ 58) = 1.

Solution: Translate the letters in STOP to their numerical equivalents 18 19 14 15.


◦ Divide into blocks of four digits (because 2525 < n=2537 < 252525) to obtain 1819 1415.
◦ Encrypt each block using the mapping C = M13 mod 2537.
◦ Since 181913 mod 2537 = 2081 and 141513 mod 2537 = 2182, the encrypted message is 2081 2182.
RSA Decryption
To decrypt a RSA ciphertext message, the decryption key d, an inverse of e modulo
(p−1)(q −1) is needed. The inverse exists since gcd(e,(p−1)(q −1)) =1.
Note that if de ≡ 1 (mod (p − 1)(q − 1)), there is an integer k such that
de = 1 + k(p − 1)(q − 1).
With the decryption key d, we can decrypt each block with the computation
M = Cd mod p∙q. (see text for full derivation)
RSA works as a public key system since the only known method of finding d is based
on a factorization of n into primes. There is currently no known feasible method for
factoring large numbers into primes.
RSA Decryption- example
Example: The message 0981 0461 is received. What is the decrypted message if it was
encrypted using the RSA cipher from the previous example.
Solution: The message was encrypted with n = 43∙ 59 = 2537 and exponent 13. An inverse
of 13 modulo 42∙ 58 = 2436 (exercise 2 in Section 4.4) is d = 937.
◦ To decrypt a block C, M = C937 mod 2537.
◦ Since 0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115, the decrypted message is 0704
1115. Translating back to English letters, the message is HELP.
◦ Here is a link to RSA calculator:
https://www.cs.drexel.edu/~jpopyack/IntroCS/HW/RSAWorksheet.html
find Estenthey

is iii iii.it
I

I iiiiiiiiiiii 72
Diffie-Hellman
The Diffie Hellman algorithm widely known as Key exchange algorithm or key agreement algorithm
developed by Whitefield Diffie and Martin Hellman in 1976. The purpose of the algorithm is to enable two
users to securely exchange a key that can be used for subsequent encryption of messages. The algorithm
itself is limited to the exchange of secret values.
Step-1: Select q (prime number) and α (α is primitive root of q)
Step-2: User A Key Generation: select XA, XA < q
Calculate public key YA, YA = αXA mod q
YA Shared with user B
Step-3: User B Key Generation: select XB, XB < q
Calculate public key YB, YB = αXB mod q
YB shared with user A
Step-4: Calculation of secret key by user A: K = (YB)XA mod q
Step-5: Calculation of secret key by user B: K = (YA)XB mod q

78
Diffie Helman Step by Step
Step – 1: Select q (prime number) and α (α is primitive root of q)
Example, here q = 7, α = 17.
Step – 2: User A Key Generation: Select XA < q,
calculate public key YA and shared with user B: YA = αXA mod q
Example, Here XA = 6,
Calculate YA = αXA mod q ⇒176 mod 7 ⇒ 1
Step – 3: User B Key Generation: Select XB < q,
calculate public key YB and shared with user A: YB = αXB mod q
Example, Here XB = 4,
Calculate YB = αXB mod q ⇒174 mod 7 ⇒ 4
Diffie Helman Step by Step- Cont
Step – 4: Calculation of secret key by user A:
K = (YB) XA mod q
Example, Here YB = 4, XA = 6
Calculate K = (YB) XA mod q ⇒46 mod 7 ⇒ 1
Step – 5: Calculation of secret key by user B:
K = (YA) XB mod q
Example, Here YA = 1, XB = 4
Calculate K = (YA) XB mod q ⇒14 mod 7 ⇒ 1
81
Cryptographic Protocols: Key Exchange
Cryptographic protocols are exchanges of messages carried out by two or more parties to achieve a particular security goal.
Key exchange is a protocol by which two parties can exchange a secret key over an insecure channel without having any past
shared secret information. Here the Diffe-Hellman key agreement protocol is described by example.
1. Suppose that Alice and Bob want to share a common key.
2. Alice and Bob agree to use a prime p and a primitive root a of p.
3. Alice chooses a secret integer k1 and sends ak1 mod p to Bob.
4. Bob chooses a secret integer k2 and sends ak2 mod p to Alice.
5. Alice computes (ak2)k1 mod p.
6. Bob computes (ak1)k2 mod p.

At the end of the protocol, Alice and Bob have their shared key
(ak2)k1 mod p = (ak1)k2 mod p.
To find the secret information from the public information would require the adversary to find k1 and k2 from ak1 mod p and
ak2 mod p respectively. This is an instance of the discrete logarithm problem, considered to be computationally infeasible
when p and a are sufficiently large.
Cryptographic Protocols: Digital Signatures
Adding a digital signature to a message is a way of ensuring the recipient that the message
came from the purported sender.
Suppose that Alice’s RSA public key is (n,e) and her private key is d. Alice encrypts a plain text
message x using E(n,e) (x)= xd mod n. She decrypts a ciphertext message y using D(n,e) (y)= yd mod
n.
Alice wants to send a message M so that everyone who receives the message knows that it
came from her.
1. She translates the message to numerical equivalents and splits into blocks m1, m2 , m3,….
just as in RSA encryption.
2. She then applies her decryption function D(n,e) to the blocks and sends the results to all
intended recipients.
3. The recipients apply Alice’s encryption function and the result is the original plain text
since E(n,e) (D(n,e) (x))= x.
Everyone who receives the message can then be certain that it came from Alice.
Cryptographic Protocols: Digital Signatures
Example: Suppose Alice’s RSA cryptosystem is the same as in the earlier example with key(2537,13),
2537 = 43∙ 59, p = 43 and q = 59 are primes and gcd(e,(p−1)(q −1)) = gcd(13, 42∙ 58) = 1.
Her decryption key is d = 937.
She wants to send the message “MEET AT NOON” to her friends so that they can be certain that
the message is from her.
Solution: Alice translates the message into blocks of digits 1204 0419 0019 1314 1413.
1. She then applies her decryption transformation D(2537,13) (x)= x937 mod 2537 to each block.
2. She finds (using her laptop, programming skills, and knowledge of discrete mathematics) that 1204937
mod 2537 = 817, 419937 mod 2537 = 555 , 19937 mod 2537 = 1310, 1314937 mod 2537 = 2173, and
1413937 mod 2537 = 1026.
3. She sends 0817 0555 1310 2173 1026.
When one of her friends receive the message, they apply Alice’s encryption transformation E(2537,13)
to each block. They then obtain the original message which they translate back to English letters.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy