0% found this document useful (0 votes)
45 views6 pages

Terna Engineering College: Class: TE Sem.: VI

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

Terna Engineering College

Computer Engineering Department

Class: TE Sem.: VI

Course: Cryptography and System Security Lab

Experiment No.02
PART B
(PART B: TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the practical. The soft
copy must be uploaded on the Blackboard or emailed to the concerned lab in charge faculties at the end
of the practical in case the there is no Black board access available)

Roll No.: 60 Name: Shubhankar Vijay Kanoje


Class: TE-A Batch: A3
Date of Experiment: 24/01/2022 Date of Submission: 4/02/2022
Grade:

B.1. Output:

B.2. Source Code of RSA Algorithm with Digital Signature:


def factors(phi):
a=set()
c=2
while phi!=1:
if phi%c==0 :
a.add(c)
phi=phi//c
else :
c+=1
return a

def calculate_keys(p, q):


e=0
d=0
n = p * q
phin = (p-1) * (q-1)
for i in range(2,phin):
factorsphi = factors(phin)
factorsi = factors(i)
if factorsi.intersection(factorsphi)==set():
e=i
break

print(f"The value of e is {e}")


for k in range(1,phin):
m=(phin*k)+1
if m%e==0:
d=m//e
break

print(f"The value of d is {d}")


return e,d,n

M=int(input("Enter a number as msg :-->"))


p,q=input("Enter two prime nos seperated by space:--> ").split()
e, d, n = calculate_keys(int(p),int(q))
print(f"Public key = ({e},{n})")
print(f"Private key = ({d},{n})")
C=M**e%n
print("The encrypted message is -->", C)
m=C**d%n
print("The decrypted msg is -->", m)
B.3 Question of Curiosity:
1. What is asymmetric key encryption?
Ans.: Asymmetric encryption is a cryptographic system that uses pairs of keys. Each pair
consists of a public key and a private key. The generation of such key pairs depends on
cryptographic algorithms which are based on mathematical problems termed one-way
functions.

2. Differentiate between symmetric and asymmetric encryption


algorithms.
Ans.:
Symmetric Key Encryption Asymmetric Key Encryption
It only requires a single key for both It requires two key one to encrypt and
encryption and decryption. the other one to decrypt.
The size of cipher text is same or smaller The size of cipher text is same or larger
than the original plain text. than the original plain text.
The encryption process is very fast. The encryption process is slow.
It is used when a large amount of data is It is used to transfer small amount of
required to transfer. data.
It provides confidentiality, authenticity
It only provides confidentiality.
and non-repudiation.
Examples: Diffie-Hellman, ECC, El
Examples: 3DES, AES, DES and RC4
Gamal, DSA and RSA
In symmetric key encryption, resource
In asymmetric key encryption, resource
utilization is low as compared to
utilization is high.
asymmetric key encryption.

3. Explain different uses of RSA algorithm.


Ans.: RSA is seen in a range of web browsers, email, VPNs, chat and other communication
channels. RSA is also often used to make secure connections between VPN clients and
VPN servers. Under protocols like OpenVPN, TLS handshakes can use the RSA algorithm
to exchange keys and establish a secure channel.
4. List and explain different possible attacks on RSA.
Ans.:
1. Plain text attacks:
It is classified into 3 subcategories: -

Short message attack:


In this we assume that 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 attacker will think that plain text is converted into cipher text using permutation
and he will apply right for conversion. But attacker does not right plain text. Hence will
keep doing it.
Unconcealed Message attack:
Sometimes happened that plain text is same as cipher text after encryption. So it must be
checked it cannot be attacked.

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 attacker will able to know P and Q using N, then he could find out value of private key.
This can be failed when N contains at least 300 longer digits in decimal terms, attacker
will not able to find. Hence it fails.

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).

5. Explain the digital signature scheme DSS.


Ans.: Digital signature is a way of authenticating a digital data coming from a trusted
source.

Digital Signature Standard (DSS) is a Federal Information Processing Standard (FIPS)


which defines algorithms that are used to generate digital signatures with the help of
Secure Hash Algorithm (SHA) for the authentication of electronic documents. DSS only
provides us with the digital signature function and not with any encryption or key
exchanging strategies.
Sender Side:
In DSS Approach, a hash code is generated out of the message and following inputs are given to
the signature function –

• The hash codes.


• The random number ‘k’ generated for that particular signature.
• The private key of the sender i.e., PR(a).
• A global public key (which is a set of parameters for the communicating principles) i.e.,
PU(g).

These input to the function will provide us with the output signature containing two
components – ‘s’ and ‘r’. Therefore, the original message concatenated with the signature is
sent to the receiver.

Receiver Side:
At the receiver end, verification of the sender is done. The hash code of the sent message is
generated. There is a verification function which takes the following inputs –

The hash code generated by the receiver. Signature


components ‘s’ and ‘r’.
Public key of the sender. Global
public key.
The output of the verification function is compared with the signature component ‘r’. Both the values
will match if the sent signature is valid because only the sender with the help of it private key can
generate a valid signature

B.4. Conclusion:
Hence, a program to implement RSA algorithm and Digital Signature scheme using RSA
has been executed using Python.

You might also like