You are on page 1of 57

Unit-3

• Prime and relatively Prime no


• Modular Arithmetic
• Euclid Theorem for GCD
• Extended Euclid theorem for the multiplicative inverse
• Principal of public key cryptosystems
• RSA Algorithm
• Security of RSA
• Key Management
• Deffie Hellmann Key Exchange Algorithm
Prime and relatively Prime no
• What are prime numbers?
• A prime number is a natural number greater than 1, which is only divisible
by 1 and itself. First, few prime numbers are: 2 3 5 7 11 13 17 19 23…..

• In other words, the prime number is a positive integer greater than 1 that
has exactly two factors, 1 and the number itself.
• There are many prime numbers, such as 2, 3, 5, 7, 11, 13, etc.
• Keep in mind that 1 cannot be either prime or composite.
• The remaining numbers, except for 1, are classified as prime and composite
numbers
Prime and relatively Prime no
Prime and relatively Prime no
Prime and relatively Prime no
Prime and relatively Prime no
Prime and relatively Prime no
How do we check whether a number is Prime or not?
Naive Approach: A naive solution is to iterate through all numbers from 2 to sqrt(n) and for every number check
if it divides n. If we find any number that divides, we return false.
Prime and relatively Prime no
Modular Arithmetic
Modular Arithmetic
Modular Arithmetic
Modular Arithmetic
Modular Arithmetic
Euclid Theorem for GCD
Euclid Theorem for GCD
Euclid Theorem for GCD
Extended Euclid Theorem
Extended Euclid Theorem
Extended Euclid Theorem
Extended Euclid Theorem
Extended Euclid Theorem
Euler’s Totient Function
• Euler’s Totient function Φ (n) for an input n is the count of numbers in
{1, 2, 3, …, n-1} that are relatively prime to n, i.e., the numbers whose
GCD (Greatest Common Divisor) with n is 1.
Euler’s Totient Function
Euler’s Totient Function
# Python3 program to calculate
# Euler's Totient Function
def phi(n):

# Initialize result as n
result = n;

# Consider all prime factors


# of n and subtract their
# multiples from result
p = 2;
while(p * p <= n):

# Check if p is a
# prime factor.
if (n % p == 0):

# If yes, then
# update n and result
while (n % p == 0):
n = int(n / p);
result -= int(result / p);
p += 1;

# If n has a prime factor


# greater than sqrt(n)
# (There can be at-most
# one such prime factor)
if (n > 1):
result -= int(result / n);
return result;

# Driver Code
for n in range(1, 11):
print("phi(",n,") =", phi(n));
Euler’s Totient Function
Euler’s Totient Function
Euler’s Totient Function
Euler’s Totient Function
Euler’s Totient Function
Euler’s Totient Function
Principal of public key cryptosystems
• Blockchain technology is one of the greatest innovations of the 21st
century. In this article, we will focus on the concept of cryptography
i.e. public-key cryptography or Asymmetric key cryptography.

• Introduction To Public-Key Cryptography


• Most of the time blockchain uses public-key cryptography, also known
as asymmetric-key cryptography. Public key cryptography uses both
public key and private key in order to encrypt and decrypt data. The
public key can be distributed commonly but the private key can not
be shared with anyone. It is commonly used for two users or two
servers in a secure way.
Principal of public key cryptosystems
Principal of public key cryptosystems

• Public Key: Public keys are designed to be public. They can be freely
given to everyone or posted on the internet. By using the public key,
one can encrypt the plain text message into the cipher text. It is also
used to verify the sender authentication. In simple words, one can say
that a public key is used for closing the lock.
• Private Key: The private key is totally opposite of the public key. The
private key is always kept secret and never shared. Using this key we
decrypt cipher text messages into plain text. In simple words, one can
say that the public is used for opening the lock.
Principal of public key cryptosystems

• Why Do We Need Public-Key Cryptography?


• In symmetric-key cryptography, a single key is used to encrypt and decrypt
the message. Here, the possibility of data loss or unauthorized access to
data is high. To overcome the unauthorized access of data and data sent
securely without any loss, we use public-key cryptography.
• Public-key cryptography is more secure than symmetric key cryptography
because the public key uses the two keys to encrypt and decrypt the data
• Public-key cryptography allows the users to hide the data that they want to
send. The sender encrypts the data and the receiver decrypts the data. The
encrypted message is not understood by unauthorized users.
Principal of public key cryptosystems
• Working On Public-Key Cryptography
• Suppose, the sender wants to send some important message to the
receiver.
• The sender first creates a message in the form of plain text which is in a
readable format.
• The sender knows the public key of the receiver but doesn’t know the
private key of the receiver because the receiver keeps secret his private
key. With the help of the public key of the receiver and the private key of
the sender, the sender generates the encrypted message i.e. called cipher
text. Cipher text is in an unreadable format. In this step, plain text converts
into cipher text.
• Now, cipher text reaches the receiver end. The receiver knows its own
private key, and with the help of the private key receiver converts the
cipher text into readable format i.e. plain text.
Principal of public key cryptosystems
Principal of public key cryptosystems
• Let’s try to under the working of public-key cryptography with an example. Suppose
Sachin is the sender who wants to send a message to Anurag. Here Anurag is the
receiver.
• Sachin uses Anurag’s public key to encrypt the message and Anurag uses his own private
key to decrypt the message.
• First Sachin creates plain text. Sachin has access to Anurag’s private key and cipher text.
Using Anurag’s public key and own public key,
• Sachin will generate an encrypted message i.e. cipher text which is in an unreadable
format. After applying the encryption process plain text converts into cipher text.
• Now, Anurag receives a cipher text. First Anurag will decrypt the cipher text message into
a readable format. For decrypting Anurag will use the private key. Now cipher text
converts into plain text and is readable by the receiver. Because Sachin keeps his private
key, Anurag knows that this message couldn’t have come from anyone else. This is also
called a digital signature.
Principal of public key cryptosystems

• Benefits of Public-key Cryptography


• Authentication: It ensures to the receiver that the data received has
been sent by the only verified sender.
• Data integrity: It ensures that the information and program are
changed only in a specific and authorized manner.
• Data confidentiality: It ensures that private message is not made
available to an unauthorized user. It is referred to as privacy or
secrecy.
• Non-repudiation: It is an assurance that the original creator of the
data cannot deny the transmission of the said data to a third party.
Principal of public key cryptosystems

• Limitation of Public-Key Cryptography


• One can encrypt and decrypt the fixed size of messages or data. If
there is an attempt to encrypt or decrypt a large size of the message
then the algorithm demands high computational power.
• The main disadvantage of this algorithm is that if the receiver losses
its private key then data/message will be lost forever.
• If someone has access private key then all data will be in the wrong
hand.
• There are many secret-key which is faster than public-key
cryptography.
RSA Algorithm in Cryptography
• RSA algorithm is an asymmetric cryptography algorithm. Asymmetric
actually means that it works on two different keys i.e. Public
Key and Private Key. As the name describes that the Public Key is given to
everyone and the Private key is kept private.
• An example of asymmetric cryptography :
• A client (for example browser) sends its public key to the server and
requests some data.
• The server encrypts the data using the client’s public key and sends the
encrypted data.
• The client receives this data and decrypts it.
• Since this is asymmetric, nobody else except the browser can decrypt the
data even if a third party has the public key of the browser.
RSA Algorithm in Cryptography
RSA Algorithm in Cryptography
RSA Algorithm in Cryptography
RSA Algorithm in Cryptography
Security of RSA
• Security of RSA:-
These are explained as following below.
• 1. Plain text attacks:
It is classified into 3 subcategories:-
• Short message attack:
In this, we assume that the attacker knows some blocks of plain text and tries to
decode cipher text with the help of that. So, to prevent this pad the plain text
before encrypting.
• Cycling attack:
In this attack, the attacker thinks that the cipher text has been generated by using
some permutation. He uses all possible permutations of plain text to decipher the
cipher text by ‘cycling’ the permutations.
• Unconcealed Message attack:
Sometimes it happens that plain text is same as cipher text after encryption. So it
must be checked or it will be of no use as the attacker will see right through it.
Security of RSA
• 2. Chosen cipher attack:
In this attacker is able to find out plain text based on cipher text using the Extended Euclidean
Algorithm.
• 3. Factorization attack:
If the attacker is able to know P and Q using N, then he can find out value of private key. This fails
when N contains at least 300 longer digits in decimal terms, attacker will not able to find it. Hence
this is infeasible for larger numbers.
• 4. Attacks on Encryption key:
If we take smaller value of E in RSA this may occur so to avoid this take value of E = 2^16+1 (at
least).
• 5. Attacks on Decryption key:
• Revealed decryption exponent attack:
If attacker somehow guess decryption key D, not only the cipher text generated by encryption the
plain text with corresponding encryption key is in danger, but even future messages are also in
danger. So, it is advised to take fresh values of two prime numbers (i.e.: P and Q), N and E.
• Low decryption exponent attack:
If we take smaller value of D in RSA this may occur so to avoid this take value of D = 2^16+1(at
least).
Key Management
• In cryptography, it is a very tedious task to distribute the public and
private keys between sender and receiver. If the key is known to the
third party (forger/eavesdropper) then the whole security mechanism
becomes worthless. So, there comes the need to secure the exchange
of keys.
• There are two aspects for Key Management:
• Distribution of public keys.
• Use of public-key encryption to distribute secrets.
• Distribution of Public Key:
• The public key can be distributed in four ways:
Key Management
• Public announcement
• Publicly available directory
• Public-key authority
• Public-key certificates.
• These are explained as following below:
• 1. Public Announcement: Here the public key is broadcasted to
everyone. The major weakness of this method is a forgery. Anyone
can create a key claiming to be someone else and broadcast it. Until
forgery is discovered can masquerade as claimed user.
Key Management
Key Management
• 2. Publicly Available Directory: In this type, the public key is stored in a public directory.
Directories are trusted here, with properties like Participant Registration, access and
allow to modify values at any time, contains entries like {name, public-key}. Directories
can be accessed electronically still vulnerable to forgery or tampering.
• 3. Public Key Authority: It is similar to the directory but, improves security by tightening
control over the distribution of keys from the directory. It requires users to know the
public key for the directory. Whenever the keys are needed, real-time access to the
directory is made by the user to obtain any desired public key securely.
• 4. Public Certification: This time authority provides a certificate (which binds an identity
to the public key) to allow key exchange without real-time access to the public authority
each time. The certificate is accompanied by some other info such as period of validity,
rights of use, etc. All of this content is signed by the private key of the certificate
authority and it can be verified by anyone possessing the authority’s public key.
First sender and receiver both request CA for a certificate which contains a public key and
other information and then they can exchange these certificates and can start
communication.
Deffie Hellmann Key Exchange Algorithm
Deffie Hellmann Key Exchange Algorithm
Deffie Hellmann Key Exchange Algorithm
Deffie Hellmann Key Exchange Algorithm
Deffie Hellmann Key Exchange Algorithm

You might also like