Introduction to Network Security
Lecture 2: Caesar and RSA
Location:E.T.S. de Ingenierias Informatica y de Telecomunicacion Universidad
de Granada 18071, Granada (SPAIN), 24-28 April 2017
Dr. Tarek Gaber
Faculty of Computers and Informatics,
Suez Canal University, Ismailia, Egypt
tmgaber@gmail.com
Lecture Objectives
To learn Caesar encryption as
an example of symmetric
encryption techniques
To learn RSA encryption as an
example of asymmetric
encryption techniques
Lecture Outlines
What is Caesar Algorithm
How does Caesar algorithm works
What is RSA technique
Simple numerical example of RSA
Caesar Cipher
• The earliest known as substitution cipher by
Julius Caesar
• First attested use in military affairs
• Replaces each letter by 3rd letter later
• example:
meet me after the toga party
PHHW PH DIWHU WKH WRJD SDUWB
http://www.xarg.org/tools/caesar-
cipher/
What is a Caesar Cipher?
• Caesar used to encrypt his messages using a very simple
algorithm, which could be easily decrypted if you know
the key.
• He would take each letter of the alphabet and replace it
with a letter a certain distance away from that letter.
When he got to the end, he would wrap back around to
the beginning.
• Example with a shift of 3:
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
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
https://www.youtube.com/watch?v=fR8rVR72a6o
Caesar Wheel
Caesar Cipher
• can define transformation as:
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
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
• mathematically give each letter a number
a b c d e f g h i j k l m
0 1 2 3 4 5 6 7 8 9 10 11 12
n o p q r s t u v w x y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
• then have Caesar cipher as:
C = E(p) = (p + k) mod (26)
p = D(C) = (C – k) mod (26)
MOD Function
• MOD is short for modulus, which means ' the remainder left
over after a value is divided by something'
Examples:
27 mod 26... 27 / 26 is 1 R 1, so 27 mod 26 is 1
53 mod 26... 53 / 26 is 2 R 1 so 53 mod 26 is also 1
10 mod 3 is also 1 (since 10 / 3 = 3 R 1)
2 mod 2 = 0
5 mod 2 = 1
25 mod 26 = 25
50 mod 26 = 24
• if a = (b) mod c then a = (c*k + b) mod c (where k = 1,2,3.......)
• So, if we have (-4 mod 3), we could write it as ( 3x2 -4) mod 3 =2
Caesar Algorithm
• 1. Convert the characters to numbers
2. Pick a number to shift by
3. Add the number to each character
4. Mod each resulting number by 26
5. You message is now encrypted!
Cryptanalysis of Caesar Cipher
• only have 26 possible ciphers
– A maps to A,B,..Z
• could simply try each in turn
• a brute force search
• given ciphertext, just try all shifts of letters
• do need to recognize when have plaintext
• eg. break ciphertext “ERE L ORYH BRX
DOLFH“ (HOMEWORK)
The Problem with Caesar’s Cipher
• It’s too easy to break! Let’s go back to our five letter alphabet.
• Say you had the word DBCA, but didn’t know the key. It would be easy to
make a list of all possible keys. If you expected the unencrypted text to be
in English, you could easily figure out which word was right:
• If you were using the full English alphabet, this would take longer, but for
someone trying to find our your secret, it’s a small price to pay!
Shift of 1 CABE
Shift of 2 BEAD  The clear winner!
Shift of 3 ADEC
Shift of 4 ECDB
How dare you
insult my cipher!
Though, you have
a good point…
RSA Algorithm
• The RSA algorithm is named after Ron Rivest, Adi Shamir and Len
Adleman, who invented it in 1977.
• The RSA cryptosystem is the most widely-used public key
cryptography algorithm in the world. It can be used to encrypt a
message without the need to exchange a secret key separately.
• The RSA algorithm can be used for both public key encryption
and digital signatures.
• Its security is based on the difficulty of factoring large integers.
Prime Number
• A Prime Number can be divided evenly only by
1 or itself and it must be a whole number
greater than 1.
• Examples:
– Is 8 a Prime Number?
• No, because it can be divided evenly by 2 or 4 (2×4=8),
as well as by 1 and 8.
– Is 73 a Prime Number?
• Yes, it can only be divided evenly by 1 and 73.
Prime and Co-prime Number
• Two numbers are said to be Co-primes when they
have only 1 as a common factor.
• Example 1: Are numbers 6 and 25 Coprime ?
Answer = Two given numbers are 6 and 25
Factors of 6 = 1, 2, 3, 6 and Factors of 25 = 1, 5, 25
On comparing the factors of numbers 6 and 25, you can see
that both have only 1 as a common factor, So, 6 and 25 are
Coprimes.
• The Factors of a given number are those which divide
a given number completely, without leaving any
remainder.
– Factors of a given number 12 are 1, 2, 3, 4, 6 & 12
RSA Key Generation Algorithm
• Generate two large random primes, p and q, of
approximately equal size such that their product n =
pq is of the required bit length, e.g. 1024 bits.
• Compute n = pq and (phi) φ = (p-1)(q-1).
• Choose an integer e, 1 < e < phi, such that gcd(e, phi)
= 1. Compute the secret exponent d, 1 < d < phi, such
that ed ≡ 1 (mod phi).
– ( e *d) / phi = ? with the remainder of 1, (1 mod phi equivalent to e*d
mod phi).
• The public key is (n, e) and the private key (p, q, d) or
(n, d).
• Keep all the values d, p, q and phi secret.
Summary of RSA
• Key Generation
– n = pq, where p and q are distinct primes.
– phi, φ = (p-1)(q-1)
– e < n such that gcd(e, phi)=1
– d = e-1 mod phi.
• Encryption/Decryption
– c = me mod n, 1<m<n.
– m = cd mod n.
Homework (Caesar and RSA)
• Using the Caesar algorithm, how you can get the key
used to get the ciphertext “ERE L ORYH BRX DOLFH“ and
what should be the plaintext of this ciphertext.
• In the RSA numerical example given in the lecture, we
have chosen e = 7,
– change e to 11,
– compute d, and
– compute the public and private key pair
– encrypt the message M =2
• Send it to tmgaber@gmai.com by 12:00 (PM) 27-4-2017
Thanks for your attention
Questions, please

Simple Overview Caesar and RSA Encryption_by_Tarek_Gaber

  • 1.
    Introduction to NetworkSecurity Lecture 2: Caesar and RSA Location:E.T.S. de Ingenierias Informatica y de Telecomunicacion Universidad de Granada 18071, Granada (SPAIN), 24-28 April 2017 Dr. Tarek Gaber Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt tmgaber@gmail.com
  • 2.
    Lecture Objectives To learnCaesar encryption as an example of symmetric encryption techniques To learn RSA encryption as an example of asymmetric encryption techniques
  • 3.
    Lecture Outlines What isCaesar Algorithm How does Caesar algorithm works What is RSA technique Simple numerical example of RSA
  • 4.
    Caesar Cipher • Theearliest known as substitution cipher by Julius Caesar • First attested use in military affairs • Replaces each letter by 3rd letter later • example: meet me after the toga party PHHW PH DIWHU WKH WRJD SDUWB http://www.xarg.org/tools/caesar- cipher/
  • 5.
    What is aCaesar Cipher? • Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key. • He would take each letter of the alphabet and replace it with a letter a certain distance away from that letter. When he got to the end, he would wrap back around to the beginning. • Example with a shift of 3: 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 D E F G H I J K L M N O P Q R S T U V W X Y Z A B C https://www.youtube.com/watch?v=fR8rVR72a6o
  • 6.
  • 7.
    Caesar Cipher • candefine transformation as: 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 D E F G H I J K L M N O P Q R S T U V W X Y Z A B C • mathematically give each letter a number a b c d e f g h i j k l m 0 1 2 3 4 5 6 7 8 9 10 11 12 n o p q r s t u v w x y Z 13 14 15 16 17 18 19 20 21 22 23 24 25 • then have Caesar cipher as: C = E(p) = (p + k) mod (26) p = D(C) = (C – k) mod (26)
  • 8.
    MOD Function • MODis short for modulus, which means ' the remainder left over after a value is divided by something' Examples: 27 mod 26... 27 / 26 is 1 R 1, so 27 mod 26 is 1 53 mod 26... 53 / 26 is 2 R 1 so 53 mod 26 is also 1 10 mod 3 is also 1 (since 10 / 3 = 3 R 1) 2 mod 2 = 0 5 mod 2 = 1 25 mod 26 = 25 50 mod 26 = 24 • if a = (b) mod c then a = (c*k + b) mod c (where k = 1,2,3.......) • So, if we have (-4 mod 3), we could write it as ( 3x2 -4) mod 3 =2
  • 9.
    Caesar Algorithm • 1.Convert the characters to numbers 2. Pick a number to shift by 3. Add the number to each character 4. Mod each resulting number by 26 5. You message is now encrypted!
  • 10.
    Cryptanalysis of CaesarCipher • only have 26 possible ciphers – A maps to A,B,..Z • could simply try each in turn • a brute force search • given ciphertext, just try all shifts of letters • do need to recognize when have plaintext • eg. break ciphertext “ERE L ORYH BRX DOLFH“ (HOMEWORK)
  • 11.
    The Problem withCaesar’s Cipher • It’s too easy to break! Let’s go back to our five letter alphabet. • Say you had the word DBCA, but didn’t know the key. It would be easy to make a list of all possible keys. If you expected the unencrypted text to be in English, you could easily figure out which word was right: • If you were using the full English alphabet, this would take longer, but for someone trying to find our your secret, it’s a small price to pay! Shift of 1 CABE Shift of 2 BEAD  The clear winner! Shift of 3 ADEC Shift of 4 ECDB How dare you insult my cipher! Though, you have a good point…
  • 12.
    RSA Algorithm • TheRSA algorithm is named after Ron Rivest, Adi Shamir and Len Adleman, who invented it in 1977. • The RSA cryptosystem is the most widely-used public key cryptography algorithm in the world. It can be used to encrypt a message without the need to exchange a secret key separately. • The RSA algorithm can be used for both public key encryption and digital signatures. • Its security is based on the difficulty of factoring large integers.
  • 13.
    Prime Number • APrime Number can be divided evenly only by 1 or itself and it must be a whole number greater than 1. • Examples: – Is 8 a Prime Number? • No, because it can be divided evenly by 2 or 4 (2×4=8), as well as by 1 and 8. – Is 73 a Prime Number? • Yes, it can only be divided evenly by 1 and 73.
  • 14.
    Prime and Co-primeNumber • Two numbers are said to be Co-primes when they have only 1 as a common factor. • Example 1: Are numbers 6 and 25 Coprime ? Answer = Two given numbers are 6 and 25 Factors of 6 = 1, 2, 3, 6 and Factors of 25 = 1, 5, 25 On comparing the factors of numbers 6 and 25, you can see that both have only 1 as a common factor, So, 6 and 25 are Coprimes. • The Factors of a given number are those which divide a given number completely, without leaving any remainder. – Factors of a given number 12 are 1, 2, 3, 4, 6 & 12
  • 15.
    RSA Key GenerationAlgorithm • Generate two large random primes, p and q, of approximately equal size such that their product n = pq is of the required bit length, e.g. 1024 bits. • Compute n = pq and (phi) φ = (p-1)(q-1). • Choose an integer e, 1 < e < phi, such that gcd(e, phi) = 1. Compute the secret exponent d, 1 < d < phi, such that ed ≡ 1 (mod phi). – ( e *d) / phi = ? with the remainder of 1, (1 mod phi equivalent to e*d mod phi). • The public key is (n, e) and the private key (p, q, d) or (n, d). • Keep all the values d, p, q and phi secret.
  • 16.
    Summary of RSA •Key Generation – n = pq, where p and q are distinct primes. – phi, φ = (p-1)(q-1) – e < n such that gcd(e, phi)=1 – d = e-1 mod phi. • Encryption/Decryption – c = me mod n, 1<m<n. – m = cd mod n.
  • 17.
    Homework (Caesar andRSA) • Using the Caesar algorithm, how you can get the key used to get the ciphertext “ERE L ORYH BRX DOLFH“ and what should be the plaintext of this ciphertext. • In the RSA numerical example given in the lecture, we have chosen e = 7, – change e to 11, – compute d, and – compute the public and private key pair – encrypt the message M =2 • Send it to tmgaber@gmai.com by 12:00 (PM) 27-4-2017
  • 18.
    Thanks for yourattention Questions, please