Chapter 2
Chapter 2
Chapter 2
CHAPTER TWO
CRYPTOGRAPH
Y
2 INTRODUCTION
The global Internet is the internationally connected network of
computer networks with addresses that are administrated by
IANA (Internet address and Naming Authority).
There are many aspects to security and many applications,
ranging from secure commerce and payments to private
communications and protecting passwords.
Network security is mostly achieved through the use of
cryptography, a science based on abstract algebra.
One essential aspect for secure communications = cryptography.
3 What is Cryptography?
The word cryptography was coined by combining two Greek words, Krypto
meaning hidden and graphene meaning writing = Secret writing.
Cryptography is the practice and study of hiding information.
It is the Art or Science of converting a plain intelligible data into
an unintelligible data and again retransforming that message into
its original form.
Aim: to make messages secure and immune to attacks.
Cryptography is about constructing and analysing protocols that prevent
third parties or the public from reading private messages; various aspects in
information security such as data confidentiality, data integrity,
authentication, and nonrepudiation (Availability and authentication) are
central to modern cryptography.
4 PURPOSE OF CRYPTOGRAPHY
Authentication: The process of proving one's identity. (The
primary forms of host-to-host authentication on the Internet
today are name-based or address-based, both of which are
notoriously weak.)
Privacy/confidentiality: Ensuring that no one can read the
message except the intended receiver.
Integrity: Assuring the receiver that the received message has
not been altered in any way from the original.
Non-repudiation: A mechanism to prove that the sender
really sent this message.
Terminologies
5
Plaintext: The original intelligible message, before being
transformed.
Cipher text: The transformed message.
Cipher (Encipher) or Encode: An algorithm for transforming
an intelligible message into one that is unintelligible by
transposition and/or substitution methods
The process of converting plaintext to cipher text using a
cipher and a key
An encryption algorithm transforms the plaintext into cipher text; a decryption algorithm
transforms the cipher text back into plaintext.
The sender uses an encryption algorithm, and the receiver uses a decryption algorithm.
6
Key: Some critical information used by the cipher, known only to the
sender& receiver
A key is a number (or a set of numbers) that the cipher, as
an algorithm, operates on.
To encrypt a message, we need an encryption algorithm, an
encryption key, and the plaintext.
These create the cipher text.
To decrypt a message, we need a decryption algorithm, a
decryption key, and the cipher text.
These reveal the original plaintext.
7 Components of Cryptography
8 Using Keys
Private keys are used for decrypting.
Public keys are used for encrypting.
9
Process of cryptography
10 Three Types of Keys
three types of keys in cryptography:
Secret key, the public key, and the private key.
The secret key, is the shared key used in symmetric-key
cryptography.
The second and the third are the public and private keys
used in asymmetric-key cryptography.
11
• Block cipher
– Ek(m) = Ek(b1)Ek(b2) …
• Stream cipher
– k = k1k2 …
– Ek(m) = Ek1(b1)Ek2(b2) …
– If k1k2 … repeats itself, cipher is periodic and the length of its period is
one cycle of k1k2 …
24 SYMMETRIC-KEY CRYPTOGRAPHY
Traditional Ciphers
these are now obsolete
We can divide traditional symmetric-key ciphers into two broad
categories: substitution ciphers and transposition ciphers
25 1. Substitution Cipher- Julius Caesar
substitutes one symbol with another- is called shift cipher
We can replace character A with D, and character T with Z.
If the symbols are digits (0 to 9), we can replace 3 with 7, and 2 with 6.
Can be either
monoalphabetic ciphers.
the plaintext is always changed to the same character (or symbol) in the
ciphertext regardless of its position in the text.
if the algorithm says that character A in the plaintext is changed to character
D, every character A is changed to character D. (one-to-one relationship)
polyalphabetic ciphers
each occurrence of a character can have a different substitute.
one-to-many relationship
character A could be changed to D in the beginning of the text, but it could
be changed to N at the middle.
Example
26
Use the shift cipher with key = 15 to encrypt the message "HELLO."
Solution
We encrypt one character at a time.
Each character is shifted 15 characters down.
Letter H is encrypted to W. Letter E is encrypted to T. The first L is encrypted to A.
The second L is also encrypted to A. And 0 is encrypted to D.
The cipher text is WTAAD.
Use the shift cipher with key = 15 to decrypt the message
"WTAAD."
Disadvantages
The encryption and decryption algorithms are known.
There are only 25 keys to try.
The language of the plaintext is known and easily recognizable.
27 2. Transposition Ciphers
there is no substitution of characters; instead, their locations
change.
A character in the first position of the plaintext may appear in
the tenth position of the cipher text.
A character in the eighth position may appear in the first
position.
In other words, a transposition cipher reorders the symbols in
a block of symbols.
A transposition cipher reorders (permutes) symbols in a block
of symbols.
28
The most widely used encryption scheme is based on the Data Encryption
Standard (DES) adopted in 1977 by the National Bureau of Standards, now the
National Institute of Standards and Technology (NIST), as Federal Information
Processing Standard 46
For DES, data are encrypted in 64-bit blocks using
a 56-bit key. The algorithm transforms 64-bit input in a series of steps into a
64-bit output.
The same steps, with the same key, are used to reverse the encryption.
34 Assignment (20%)
Stream ciphers
DES
AES
Public Key Cryptography/Asymmetric
RSA
Diffie Hellman
Hashing
48 Public Key /Asymmetric Cryptography
Is a class of cryptographic algorithms which requires two separate
keys.
One of the keys allocated to each person is called the "public key",
and is published in an open directory somewhere where anyone can
easily look it up and secret or private.
In asymmetric or public-key cryptography, there are two keys :
Private Key (a secret)
Public key (well known).
The private key is kept by the receiver.
The public key is announced to the public.
Alice wants to send a message to Bob.
Alice uses the public key to encrypt the message.
When the message is received by Bob, the private key is used to decrypt the
message.
49
51
52 Public key encryption algorithms
Requirements:
1
.+ K ( ) such that-
need K ( ) and .
B B
- +
K (K (m)) = m
B B
given public key K , it should +be impossible to
2 compute private key K B
-
B
53
54 RSA
Public-key cryptography, also known as asymmetric cryptography, uses two
different but mathematically linked keys, one public and one private.
The public key can be shared with everyone, whereas the private key must be kept
secret.
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 ϕ=(p−1)(q−1).
Choose an integer e, 1<e<ϕ, such that gcd(e,ϕ)=1.
Compute the secret exponent d, 1<d<ϕ, such that ed≡1modϕ.
The public key is (n,e) and the private key (d,p,q).
Keep all the values d, p, q and ϕ secret. [Sometimes the private key is written as (n,d) because
you need the value of n when using d. Other times we might write the key pair as ((N,e),d).]
n is known as the modulus.
e is known as the public exponent or encryption exponent or just the exponent.
d is known as the secret exponent or decryption exponent.
RSA: Choosing keys
1. Choose two large prime numbers p, q.
(e.g., 1024 bits each)
Magic d
m = (m e mod n) mod n
happens!
c
56
Encryption
• Sender A does the following:-
– Obtains the recipient B's public key (n,e).
– Represents the plaintext message as a positive
integer m with 1<m<n.
e
– Computes the ciphertext c=m modn.
– Sends the ciphertext c to B.
57
Decryption
• Recipient B does the following:-
• Uses his private key (n,d) to compute
m=cdmodn.
• Extracts the plaintext from the message
representative m.
58
59
RSA Algorithm
• Choose 2 distinct prime numbers.
– p = 3 and q = 11.
• Compute n = p * q = 3 * 11 = 33
• Compute the Totient function
– φ(n) = (p - 1) * (q - 1) = 2 * 10 = 20
• Choose e such that 1 < e < φ(n) and e and n are coprime.
Let e = 7
• Compute a value for d such that (d * e) % φ(n) = 1.
– Lets say d = 3 i.e. [(3 * 7) % 20 = 1]
In RSA, e and n are announced to the public; d and are kept secret.
60
• BUT HOW TO FIND
THE VALUE OF d?
61
• Step-1: Choose two prime number p and q
• Step-2: Compute the value of
• Given as
• Step-3: Find the value of (public key)
• Step-4: Compute the value of (private key)
62
63
Exercises
• Let p=7, q=17 and e=5 find the public key
and private key.
• Change the value of e to 7 and find the
value of private key
• If p=7 and q=11. Let the value of e be 13
and find the private key and public key.
64
Exercise
• Bob chooses 7 and 11 as p and q and calculates n =
7 . 11 = 77.
• The value of <p = (7 - 1) (11 - 1) or 60.
• Now he chooses two keys, e and d. If he chooses e
to be 13, then d is 37.
• Now imagine Alice sends the plaintext 5 to Bob.
• She uses the public key 13 to encrypt 5.
• Show how Bob can send a message to Alice
if he knows e and n.
65
Solution
66
67
Where is the security?
• What problem must you solve to discover d?
• Public key: (e, n); private key: d
68
Security Services
• Confidentiality
– Only the owner of the private key knows it, so
text enciphered with public key cannot be read
by anyone except the owner of the private key
• Authentication
– Only the owner of the private key knows it, so
text enciphered with private key must have
been generated by the owner
69
More Security Services
• Integrity
– Enciphered letters cannot be changed
undetectably without knowing private key
• Non-Repudiation
– Message enciphered with private key came
from someone who knew it
70
Example: Confidentiality
• Take p = 7, q = 11, so n = 77 and (n) = 60
• Alice chooses e = 17, making d = 53
• Bob wants to send Alice secret message HELLO
(07 04 11 11 14)
– 0717 mod 77 = 28
– 0417 mod 77 = 16
– 1117 mod 77 = 44
– 1117 mod 77 = 44
– 1417 mod 77 = 42
• Bob sends 28 16 44 44 42
71
Example
• Alice receives 28 16 44 44 42
• Alice uses private key, d = 53, to decrypt message:
– 2853 mod 77 = 07
– 1653 mod 77 = 04
– 4453 mod 77 = 11
– 4453 mod 77 = 11
– 4253 mod 77 = 14
• Alice translates message to letters to read HELLO
– No one else could read it, as only Alice knows her
private key and that is needed for decryption
72
Example:
Integrity/Authentication
• Take p = 7, q = 11, so n = 77 and (n) = 60
• Alice chooses e = 17, making d = 53
• Alice wants to send Bob message HELLO (07 04 11 11
14) so Bob knows it is what Alice sent (no changes in
transit, and authenticated)
– 0753 mod 77 = 35
– 0453 mod 77 = 09
– 1153 mod 77 = 44
– 1153 mod 77 = 44
– 1453 mod 77 = 49
• Alice sends 35 09 44 44 49
73
Example
• Bob receives 35 09 44 44 49
• Bob uses Alice’s public key, e = 17, n = 77, to decrypt message:
– 3517 mod 77 = 07
– 0917 mod 77 = 04
– 4417 mod 77 = 11
– 4417 mod 77 = 11
– 4917 mod 77 = 14
• Bob translates message to letters to read HELLO
– Alice sent it as only she knows her private key, so no one else could have
enciphered it
– If (enciphered) message’s blocks (letters) altered in transit, would not
decrypt properly
74
Example: Both
• Alice wants to send Bob message HELLO both enciphered
and authenticated (integrity-checked)
– Alice’s keys: public (17, 77); private: 53
– Bob’s keys: public: (37, 77); private: 13
• Alice enciphers HELLO (07 04 11 11 14):
– (0753 mod 77)37 mod 77 = 07
– (0453 mod 77)37 mod 77 = 37
– (1153 mod 77)37 mod 77 = 44
– (1153 mod 77)37 mod 77 = 44
– (1453 mod 77)37 mod 77 = 14
• Alice sends 07 37 44 44 14
75
Diffie-Hellman Key Exchange
• RSA is a public-key cryptosystem that is often
used to encrypt and decrypt symmetric keys.
• Diffie-Hellman, on the other hand, was
originally designed for key exchange.
• In the Diffie-Hellman cryptosystem, two
parties create a symmetric session key to
exchange data without having to remember or
store the key for future use.
76
• They do not have to meet to agree on the key; it can
be done through the Internet.
• Let us see how the protocol works when Alice and Bob
need a symmetric key to communicate.
• Before establishing a symmetric key, the two parties need
to choose two numbers p and g. The first number, p, is a
large prime number on the order of 300 decimal digits
(1024 bits).
• The second number is a random number.
• These two numbers need not be confidential.
• They can be sent through the Internet; they can be public.
77
78
• The symmetric key for the session is K
79
80
Example
• Assume g =7 and p =23.
81
82 Attacks of cryptography