Information Security

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Q1.

EXPLAIN AES Algorithm with an example


The AES (Advanced Encryption Standard) algorithm is a method used to keep
information secure by encrypting it. Here’s how it works :

Encryption and Decryption: AES can turn readable data (plain text) into a
secret code (cipher text) and then back to readable data using a key.

Key Size: AES uses keys that can be 128, 192, or 256 bits long. A longer key
means stronger security.

Blocks: AES processes data in blocks of 16 bytes (128 bits) at a time. If the
data is longer, it gets divided into multiple blocks.

Rounds: Depending on the key size, AES performs a series of transformations


on the data. For example, with a 128-bit key, it does 10 rounds of mixing and
scrambling the data.

Security: AES is widely used and trusted because it is very difficult for
someone to break the code without the right key.

Example:- Encryption.

Q2.EXPLAIN DES Algorithm WITH AN EXAMPLE

The Data Encryption Standard (DES) is a symmetric-key block cipher that was
established as a federal standard for encrypting sensitive but unclassified
information.

Key Features of DES:

Symmetric Encryption: The same key is used for both encryption and
decryption, meaning that both the sender and receiver must have access to
the secret key.

Block Size: DES processes data in fixed blocks of 64 bits.

Key Size: The effective key length is 56 bits, although the key is originally
supplied as a 64-bit key (with every 8th bit used for parity).

Rounds: DES uses a total of 16 rounds of processing to enhance security.


Each round involves substitution and permutation operations.

Example of DES:

1. Key Generation: You choose a secret key (e.g., "MYSECRET").


2. Plaintext: You have a message you want to encrypt (e.g., "HELLO1234").

Q3.Explain OTP with an example


The One-Time Pad (OTP) is a cryptographic technique used for secure
communication. It is considered the only theoretically unbreakable encryption
method when implemented correctly.

Key Features of OTP:

Key Length: The key used for encryption is the same length as the message
being encrypted.

Randomness: The key must be completely random and never reused (hence
"one-time").

Key Distribution: The key must be securely shared between the sender and
recipient before communication begins.

Encryption Process: Each bit or character of the plaintext is combined with


the corresponding bit or character of the key using the XOR operation.

How OTP Works:

Encryption:

1. Plaintext: A message that needs to be encrypted (e.g., "HELLO").


2. Key: A random key of the same length as the plaintext (e.g., "XMCKL").
3. Each letter is converted to a numerical value (A=0, B=1, ..., Z=25).
4. The numerical values of the plaintext and key are added together
modulo 26 to produce the ciphertext.

Example:

Plaintext: H E L L O -> 7 4 11 11 14 Key: X M C K L -> 23 12 2 10


11 Ciphertext: C Q N V Z -> 2 16 13 21 25

Decryption:

1. The ciphertext can be decrypted by subtracting the key from the


ciphertext and taking the result modulo 26.

Example:

Ciphertext: C Q N V Z -> 2 16 13 21 25 Key: X M C K L -> 23 12 2


10 11 Plaintext: H E L L O -> 7 4 11 11 14

Advantages:

 Theoretical Security: If used correctly (with a truly random key that is as long
as the message and never reused), OTP provides perfect secrecy.

Disadvantages:
 Key Management: The major challenge is the secure generation and
distribution of the keys.
 Key Length: Requires a key that is at least as long as the message, making it
impractical for large amounts of data.

Q4.Explain RSA Algorithm with an example

RSA Algorithm - Overview

The RSA (Rivest-Shamir-Adleman) algorithm is a widely used public-key


cryptographic system that enables secure data transmission. It is primarily used for
secure key exchange, digital signatures, and encryption.

Key Features of RSA:

1. Asymmetric Encryption: RSA uses two keys, one public (for encryption) and
one private (for decryption).
2. Foundation: It relies on the mathematical properties of large prime numbers
and the difficulty of factoring their product.

Steps in RSA:

Key Generation:

1. Select two large prime numbers ppp and qqq.


2. Compute n=p×qn = p \times qn=p×q. This nnn is used as the modulus.
3. Compute ϕ(n)=(p−1)×(q−1)\phi(n) = (p-1) \times (q-
1)ϕ(n)=(p−1)×(q−1), where ϕ(n)\phi(n)ϕ(n) is Euler's totient function.
4. Choose a public key eee such that 1<e<ϕ(n)1 < e < \phi(n)1<e<ϕ(n)
and gcd(e,ϕ(n))=1\text{gcd}(e, \phi(n)) = 1gcd(e,ϕ(n))=1.
5. Calculate the private key ddd such that d×emod ϕ(n)=1d \times e
\mod \phi(n) = 1d×emodϕ(n)=1 (i.e., ddd is the modular multiplicative
inverse of eee).

Encryption:

1. Convert the plaintext message MMM into an integer mmm such that
0≤m<n0 \leq m < n0≤m<n.
2. Compute the ciphertext c=memod nc = m^e \mod nc=memodn.

Decryption:

1. Compute the plaintext m=cdmod nm = c^d \mod nm=cdmodn.


Example:

· Key Generation:

 · Choose p=61p = 61p=61, q=53q = 53q=53.


 n=61×53=3233n = 61 \times 53 = 3233n=61×53=3233,
ϕ(n)=(61−1)(53−1)=3120\phi(n) = (61-1)(53-1) =
3120ϕ(n)=(61−1)(53−1)=3120.
 Choose e=17e = 17e=17 (it satisfies gcd(17,3120)=1\text{gcd}(17, 3120) =
1gcd(17,3120)=1).
 Calculate ddd: d×17mod 3120=1d \times 17 \mod 3120 = 1d×17mod3120=1,
so d=2753d = 2753d=2753.

Public key: (e,n)=(17,3233)(e, n) = (17, 3233)(e,n)=(17,3233)


Private key: (d,n)=(2753,3233)(d, n) = (2753, 3233)(d,n)=(2753,3233)

· Encryption:

 · Suppose the plaintext message M=65M = 65M=65.


 Convert to ciphertext: c=6517mod 3233=2790c = 65^{17} \mod 3233 =
2790c=6517mod3233=2790.

· Decryption:

 · Convert back to plaintext: m=27902753mod 3233=65m = 2790^{2753}


\mod 3233 = 65m=27902753mod3233=65.
Q5.Explain RSA digital Signature with an example

An RSA digital signature is a cryptographic method used to verify the authenticity


and integrity of a message. It ensures that the message comes from the claimed
sender (authenticity) and that it has not been tampered with (integrity). Here's how
it works:

Steps in RSA Digital Signature:

Key Generation (same as regular RSA):

1. Generate a pair of keys: a public key (e,n)(e, n)(e,n) and a private key
(d,n)(d, n)(d,n).

Signing:

1. The sender generates a message digest hhh (a hash of the message)


using a hash function (e.g., SHA-256).
2. Encrypt the digest hhh with the sender's private key ddd:
S=hdmod nS = h^d \mod nS=hdmodn.
This SSS is the digital signature.

Verification:

1. The receiver computes the hash of the received message, h′h'h′.


2. Decrypt the signature SSS using the sender's public key eee:
h=Semod nh = S^e \mod nh=Semodn.
3. If hhh (from the signature) matches h′h'h′ (computed from the
message), the signature is valid.

Example:

Key Generation:

1. Choose p=61p = 61p=61, q=53q = 53q=53.


n=3233n = 3233n=3233, ϕ(n)=3120\phi(n) = 3120ϕ(n)=3120.
Public key: (e,n)=(17,3233)(e, n) = (17, 3233)(e,n)=(17,3233), Private
key: (d,n)=(2753,3233)(d, n) = (2753, 3233)(d,n)=(2753,3233).
Q6.Explain Hash function with an example.

A hash function is a mathematical function that takes an input (data) and converts it
into a fixed-size string of characters, called a hash or digest. Hash functions are
widely used in cryptography, data integrity, and indexing.

Key Features:

1. Fixed Output Size: Regardless of input size, the output hash always has a
fixed length.
2. Deterministic: The same input always produces the same output.
3. Irreversible: It's nearly impossible to reverse the hash to get the original
input.
4. Collision-Resistant: It's hard to find two different inputs with the same hash.

Example:

Hash Function: Let's use a simple hash function:


h(x) = (sum of ASCII values of characters in x) mod 10.

Example Input:

Input: "cat"
ASCII values: 'c' = 99, 'a' = 97, 't' = 116
Sum = 99+97+116=31299 + 97 + 116 = 31299+97+116=312
Hash: 312mod 10=2312 \mod 10 = 2312mod10=2.

Input: "dog"
ASCII values: 'd' = 100, 'o' = 111, 'g' = 103
Sum = 100+111+103=314100 + 111 + 103 = 314100+111+103=314
Hash: 314mod 10=4314 \mod 10 = 4314mod10=4.
Q7.Explain SSL with an example.

SSL (Secure Sockets Layer) is a standard security technology used to establish an


encrypted link between a web server and a browser (or any two systems). This
ensures that all data transmitted between them remains private and secure.

How SSL Works:

Handshake:

1. When you visit a secure website (e.g., one using HTTPS), your browser
and the server initiate an SSL handshake.
2. The server sends its SSL certificate to prove its identity.

Encryption:

1. The browser verifies the certificate and creates a session key.


2. This key is used to encrypt the data exchanged between the browser
and the server.

Secure Communication:

1. All data (e.g., login credentials, payment details) transmitted over this
link is encrypted and safe from eavesdropping.

Example:

 You visit a bank's website (e.g., https://bank.com).


 SSL encrypts your sensitive information (e.g., username and password) so
that even if someone intercepts the data, they can't read it.

Without SSL:
username=JohnDoe&password=1234 → (sent as plain text, visible to attackers).

With SSL:
Data is encrypted and might look like:
7fj39kfj#%Tyu9@lkdhs3$&*k.

Key Benefits:

 Data Security: Encrypts sensitive information.


 Trust: Websites with SSL show a padlock symbol and "HTTPS" in the browser,
assuring users of secure communication.
Q8.Explain all properties of hash function i short

Here are the main properties of a hash function in short:

Deterministic:

1. The same input always produces the same hash output.

Fixed Output Size:

1. The hash value (digest) is always of a fixed size, regardless of the input
size (e.g., SHA-256 always gives a 256-bit hash).

Efficient to Compute:

1. Hashing an input should be quick and computationally efficient.

Pre-image Resistance:

1. It should be nearly impossible to reverse a hash to find the original


input.

Collision Resistance:

1. It should be very hard to find two different inputs that produce the
same hash.

Avalanche Effect:

1. A small change in the input should drastically change the hash output.

Uniqueness:

1. Each unique input should ideally produce a unique hash (though


collisions are theoretically possible, good hash functions minimize this
risk).

Independent of Input Size:

1. The hash function can handle inputs of arbitrary size and reduce them
to a fixed-size output.

Example:

For the input "hello", SHA-256 produces:


2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824.

 Changing the input to "Hello" (capital "H") gives a completely different hash.
Q9.write a program to create large prime number of size 2048bits

from sympy import randprime


import random
def generate_large_prime(bits):
"""
Generate a large prime number of the specified bit size.
"""
# Define the range for the 2048-bit number
lower_bound = 2**(bits - 1)
upper_bound = 2**bits - 1

# Generate a random prime within the range


prime = randprime(lower_bound, upper_bound)
return prime

# Generate a 2048-bit prime


bit_size = 2048
large_prime = generate_large_prime(bit_size)
print(f"Generated 2048-bit prime:\n{large_prime}")

Output:

Generated 2048-bit prime:

32317006071311007300714876688669951960444102669715484032130345427524
6551...
Q10.Explain public key infrastructure in short

Public Key Infrastructure (PKI) is a framework of technologies, policies, and


procedures used to manage, distribute, and validate digital certificates and public-
private key pairs. It enables secure communication and identity verification over
untrusted networks, like the internet.

Key Components of PKI:

Certificate Authority (CA):

1. Issues and manages digital certificates, ensuring they are trusted.


2. Verifies the identity of entities (individuals, organizations).

Registration Authority (RA):

1. Assists the CA by verifying users' identities before certificates are


issued.

Digital Certificates:

1. Acts like a "digital passport," binding a public key to the identity of its
owner.
2. Contains information such as the public key, owner's details, CA's
signature, and expiration date.

Public and Private Keys:

1. Public Key: Shared openly and used for encryption or verifying


signatures.
2. Private Key: Kept secret and used for decryption or creating
signatures.

Certificate Revocation List (CRL)

1. A list of revoked certificates that are no longer trusted.

How PKI Works:

1. A user requests a digital certificate from the CA.


2. The RA verifies the user’s identity.
3. The CA issues the certificate containing the user’s public key and its signature.
4. Other users or systems can verify the certificate's authenticity using the CA’s
public key.
Example:

 When you visit a secure website (e.g., https://example.com), the website


uses its digital certificate (issued by a trusted CA) to prove its identity to your
browser.
 Your browser uses PKI to ensure the certificate is valid and the connection is
secure.

You might also like