CNS Viva Preparation
CNS Viva Preparation
1_GTU_Syllabus_Cryptography and …
PDF
Feel free to ask any specific questions regarding your Cryptography and Network Security
viva. Whether it's about theoretical concepts, lab exercises, or coding implementations, I'll be
happy to help!
Here’s a detailed explanation of encryption and decryption techniques using the mentioned
ciphers:
1. Caesar Cipher
Encryption: Shifts each letter in the plaintext by a fixed number (key).
For example, with a key of 3:
Plaintext: HELLO
Encrypted: KHOOR
Formula: Encrypted letter = (Plain letter's ASCII + Shift) % 26 .
Decryption: Shifts each letter in the ciphertext by the negative of the key.
Formula: Decrypted letter = (Encrypted letter's ASCII - Shift + 26) % 26 .
Example:
1/43
Key = 3
Plaintext: ABC
Encrypted: DEF
Decrypted: ABC
2. Hill Cipher
Encryption: Uses linear algebra and a matrix multiplication to encrypt blocks of
plaintext.
Plaintext is divided into pairs, and each pair is multiplied with the key matrix modulo
26.
Example:
Plaintext: HI
Encrypted:
3 3 7 9
C =K ⋅P mod 26 = [ ][ ] mod 26 = [ ]
2 5 8 24
→ Ciphertext: JY .
Decryption: Involves finding the inverse of the key matrix modulo 26 and multiplying it
with the ciphertext vector.
3. Mono-alphabetic Cipher
2/43
Encryption: Replaces each plaintext character with a corresponding character in a
shuffled alphabet.
Ciphertext: KHOOR
Plaintext: HELLO .
Example:
Key: A → M, B → N, ..., Z → L
Decrypted: HELLO .
4. Playfair Cipher
Encryption: Uses a 5x5 key matrix (constructed from a keyword). Letters are paired, and
based on their positions in the matrix:
Example:
Keyword: MONARCHY
Key Matrix:
mathematica
M O N A R
C H Y B D
E F G I K
3/43
L P Q S T
U V W X Z
Pair: HE → CF , LL → PP .
5. Vigenère Cipher
Encryption: Uses a repeating keyword to create shifts for each letter.
Example:
Plaintext: HELLO
Encryption:
mathematica
H + K → R
E + E → I
L + Y → J
L + K → V
O + E → S
Ciphertext: RIJVS .
Example:
Ciphertext: RIJVS
Keyword: KEY
Decrypted: HELLO .
4/43
These ciphers illustrate different approaches to encryption and decryption, from simple
substitutions (Caesar and Mono-alphabetic) to matrix-based (Hill), digraph (Playfair), and
polyalphabetic techniques (Vigenère).
Formula
Xn+1 = (a ⋅ Xn + c) mod m
Where:
a: Multiplier.
c: Increment.
m: Modulus (determines the range of values).
Xn : Current state.
Properties
1. The values of a, c, m, and X0 determine the quality and period of the generator.
2. Full period: The generator can produce all integers between 0 and m − 1 before
repeating, achieved if:
Example
Given:
X0 = 5 (seed),
a = 7,
5/43
c = 3,
m = 16,
X1 = (7 ⋅ 5 + 3) mod 16 = 38 mod 16 = 6
X2 = (7 ⋅ 6 + 3) mod 16 = 45 mod 16 = 13
X3 = (7 ⋅ 13 + 3) mod 16 = 94 mod 16 = 14
Advantages
Disadvantages
Formula
Where:
Output
6/43
The random bit stream is derived from the least significant bit (LSB) or a subset of bits of Xn .
Steps
Example
Given:
p = 7,
q = 11,
M = 7 ⋅ 11 = 77,
Seed X0 = 3,
X1 = (32 ) mod 77 = 9
X2 = (92 ) mod 77 = 4
X3 = (42 ) mod 77 = 16
Advantages
Disadvantages
Requires large primes, making it slower than simpler PRNGs like LCG.
7/43
Comparison
Feature LCG Blum Blum Shub (BBS)
Predictability Easy to predict if parameters known Hard to predict due to factoring problem
Both algorithms serve different purposes: LCG is suitable for general-purpose randomness,
while BBS is designed for cryptographic security.
Encryption
Example:
Number of Rails: 3
mathematica
H O R
E L W L D
L O
8/43
Decryption
2. Place the ciphertext characters in their respective positions according to the zigzag
pattern.
Example:
Ciphertext: HORLWLDLO
Number of Rails: 3
mathematica
H O R
E L W L D
L O
Encryption
2. Write the plaintext row by row in a grid where the number of columns equals the length
of the keyword.
Example:
9/43
Plaintext: HELLO WORLD
Keyword: ZEBRA
mathematica
Z E B R A
H E L L O
W O R L D
Rearrange the columns based on the alphabetical order of ZEBRA (A, B, E, R, Z):
mathematica
A B E R Z
O L E L H
D R O L W
Decryption
1. Determine the number of rows from the length of the ciphertext and the keyword.
2. Arrange the ciphertext in columns based on the alphabetical order of the keyword.
Example:
Ciphertext: OLODRELEHLW
Keyword: ZEBRA
mathematica
A B E R Z
O L E L H
D R O L W
Reorder to ZEBRA :
10/43
mathematica
Z E B R A
H E L L O
W O R L D
Encryption Process Write in zigzag, read row-wise Write in rows, read column-wise
Both methods are transposition ciphers that rearrange the characters of the plaintext
without changing the actual characters, but the Columnar Cipher is generally more secure
due to the use of a keyword.
Encryption Process
1. Initial Permutation (IP):
11/43
The 64-bit plaintext is permuted based on a fixed permutation table.
Split the permuted plaintext into two halves: Left (L) and Right (R), each of 32 bits.
Key Mixing: XOR the expanded Right half with a 48-bit subkey.
Swap: The output of the permutation is XORed with the Left half. The Right half
becomes the new Left half for the next round.
After 16 rounds, the Left and Right halves are combined and permuted using the
inverse of the initial permutation.
Example:
Plaintext: 0123456789ABCDEF
Key: 133457799BBCDFF1
Decryption Process
Decryption in DES uses the same steps as encryption, but the subkeys are applied in reverse
order (i.e., from round 16 to round 1).
Drawbacks of DES
1. Short Key Length:
12/43
DES uses a 56-bit key, which is now considered insecure due to the advancement of
computational power (brute-force attacks can break it).
2. Block Size:
The 64-bit block size is small for modern encryption needs and can lead to patterns
in ciphertext when encrypting large datasets.
3. Vulnerability to Cryptanalysis:
4. Lack of Scalability:
DES does not support variable key lengths, making it inflexible compared to modern
ciphers.
1. Encryption:
Ciphertext C = EK2 (EK1 (P )), where P is the plaintext, and K1, K2 are two
different keys.
2. Decryption:
Meet-in-the-Middle Attack:
Concept: Even with two keys, Double DES is susceptible to this attack, which reduces the
effective key space from 2112 to 257 .
How it works:
1. For known plaintext P and ciphertext C , calculate intermediate values for all
possible K1: EK1 (P ).
13/43
Triple DES (3DES)
Triple DES addresses the shortcomings of Double DES by encrypting the data three times
using two or three keys.
Modes:
Advantages:
Drawbacks:
Comparison
Feature DES Double DES Triple DES
14/43
Feature DES Double DES Triple DES
Conclusion
While DES played a significant role in the history of cryptography, its vulnerabilities have
rendered it obsolete for modern applications. Triple DES offers improved security but is now
being replaced by Advanced Encryption Standard (AES) due to its efficiency and stronger
resistance to cryptanalysis.
Number of Rounds:
Mode of Operation: Encrypts data in blocks (e.g., CBC, ECB, GCM, etc.).
15/43
Steps in AES Encryption
AES operates on a 4x4 matrix of bytes called the state. Each step manipulates this state to
produce ciphertext.
1. Key Expansion
The initial key is expanded into multiple round keys using the AES key schedule algorithm.
Each round uses a unique key derived from this expansion.
2. Initial Round
AddRoundKey: The plaintext matrix (state) is XORed with the first round key.
1. SubBytes:
Each byte in the state is replaced with a corresponding byte from the S-box
(substitution box).
2. ShiftRows:
3. MixColumns:
Each column of the state is transformed using a fixed matrix multiplication over a
Galois Field (GF(2⁸)).
4. AddRoundKey:
The state is XORed with the round key for the current round.
4. Final Round
The final round excludes the MixColumns step and only performs:
16/43
SubBytes
ShiftRows
AddRoundKey
1. Inverse AddRoundKey.
4. Inverse MixColumns.
Decryption applies the round keys in reverse order, starting with the last round key.
3. Process:
Initial AddRoundKey.
4. Ciphertext: 69c4e0d86a7b0430d8cdb78070b4c55a .
17/43
Detailed Explanation of AES Components
1. SubBytes:
Uses a substitution box (S-box) to replace each byte in the state with a
corresponding byte.
2. ShiftRows:
3. MixColumns:
Each column of the state is mixed using a matrix multiplication. This step diffuses
the bits across the entire column.
4. AddRoundKey:
XORs the state with the round key, ensuring the ciphertext is dependent on the
encryption key.
Advantages of AES
1. Security:
2. Flexibility:
AES supports variable key sizes and is efficient for both hardware and software
implementations.
3. Speed:
AES is faster than older algorithms like DES, especially with modern CPUs
supporting hardware acceleration (e.g., Intel AES-NI).
4. Standardization:
18/43
Drawbacks of AES
1. Key Management:
Proper key management is crucial; losing the key renders encrypted data
inaccessible.
2. Block Size:
Fixed block size (128 bits) might be insufficient for certain applications, requiring
additional modes of operation like GCM or CBC.
AES vs DES
Feature AES DES
Conclusion
AES is a robust and efficient encryption standard designed to meet modern security
requirements. Its flexibility, speed, and resistance to cryptanalysis have made it the default
choice for encrypting sensitive data in various applications, from securing government
communications to protecting online banking transactions.
19/43
The RSA (Rivest–Shamir–Adleman) algorithm is an asymmetric cryptographic algorithm. It
uses a pair of keys: a public key for encryption and a private key for decryption. RSA is
based on the mathematical difficulty of factoring the product of two large prime numbers,
making it highly secure.
1. Key Generation
2. Compute n:
n=p⋅q
ϕ(n) = (p − 1) ⋅ (q − 1)
ϕ(n) is the number of integers less than n that are relatively prime to n.
4. Choose Public Key e:
20/43
2. Encryption
C = Me mod n
3. The ciphertext C is sent to the receiver.
3. Decryption
M = Cd mod n
2. The original message M is recovered.
n = p ⋅ q = 17 ⋅ 11 = 187
ϕ(n) = (p − 1) ⋅ (q − 1) = 16 ⋅ 10 = 160
2. Choose e = 7 (common value):
gcd(7, 160) = 1
3. Compute d (modular inverse of e mod ϕ(n)):
d = 23
4. Public Key: (e, n) = (7, 187).
Private Key: (d, n) = (23, 187).
21/43
Step 2: Encryption
Plaintext: M = 88.
Compute ciphertext C :
Simplifying:
Ciphertext: C = 11.
Step 3: Decryption
Ciphertext: C = 11.
Compute plaintext M :
Simplifying:
Plaintext: M = 88.
Advantages of RSA
1. Asymmetric: No need to share private keys, improving security.
22/43
Disadvantages of RSA
1. Slow: Computationally intensive compared to symmetric algorithms.
2. Large Key Size: Requires large keys (1024 bits or more) for adequate security.
Security of RSA
RSA's security relies on:
Applications of RSA
1. Secure Communications:
2. Digital Signatures:
3. Key Exchange:
RSA remains a cornerstone of modern cryptography, but with the advent of quantum
computing, its security may face challenges, making post-quantum algorithms a research
priority.
23/43
Euclid's Algorithm for GCD
Euclid's Algorithm is a simple and efficient method for finding the greatest common divisor
(GCD) of two integers. The GCD of two integers is the largest integer that divides both
numbers without leaving a remainder.
r=a mod b
2. Replace a with b and b with r .
Example
1. 98 mod 56 = 42
Replace a = 56, b = 42.
2. 56 mod 42 = 14
Replace a = 42, b = 14.
3. 42 mod 14 = 0.
GCD is 14.
GCD(a, b) = ax + by
24/43
where x and y are integers (called the coefficients).
This property is particularly useful in cryptography for finding the modular multiplicative
inverse of a number.
GCD = ax + by
Recursive Implementation
1. Base Case:
If b = 0, then GCD(a, b) = a, x = 1, y = 0.
2. Recursive Step:
Backtrack using:
a
x = y1 , y = x1 − ⌊ ⌋ ⋅ y 1
Example
98 mod 56 = 42
56 mod 42 = 14
25/43
42 mod 14 = 0
GCD = 14.
14 = 56 − 1 ⋅ 42
42 = 98 − 1 ⋅ 56
Substitute:
14 = 56 − 1 ⋅ (98 − 1 ⋅ 56)
Simplify:
14 = 2 ⋅ 56 − 1 ⋅ 98
Coefficients: x = 2, y = −1.
Applications
1. Cryptography:
2. Diophantine Equations:
Key Properties
1. Efficiency:
2. Extended Algorithm:
26/43
This algorithm is a foundational tool in number theory and is indispensable in cryptographic
systems like RSA.
Key Features
1. Asymmetric Process: Uses mathematical properties of modular arithmetic and discrete
logarithms.
2. Secure: The shared secret is computed independently by both parties and never
transmitted.
Choose a primitive root g modulo p (a number whose powers generate all integers
modulo p).
2. Private Keys:
27/43
3. Compute Public Keys:
This shared secret S can now be used as a symmetric key for encrypting communication.
Example of Diffie-Hellman
1. Public Parameters:
Alice chooses a = 6.
Bob chooses b = 15.
3. Compute Public Keys:
Alice computes:
A = ga mod p = 56 mod 23 = 15625 mod 23 = 8
Bob computes:
B = gb mod p = 515 mod 23 = 30517578125 mod 23 = 19
4. Exchange Public Keys:
28/43
Alice sends A = 8 to Bob.
Bob sends B = 19 to Alice.
5. Compute Shared Secret:
Alice computes:
S = Ba mod p = 196 mod 23 = 47045881 mod 23 = 2
Bob computes:
S = Ab mod p = 815 mod 23 = 35184372088832 mod 23 = 2
1. Setup:
Mallory knows both shared secrets and can decrypt, alter, and re-encrypt messages.
4. Result:
Mallory can read and manipulate the messages between Alice and Bob without their
knowledge.
29/43
Preventing MITM Attack
1. Authentication Mechanisms:
For example, combine Diffie-Hellman with protocols like TLS (Transport Layer
Security).
2. Pre-Shared Secrets:
Exchange a password or secret key offline to verify the authenticity of public keys.
Advantages of Diffie-Hellman
1. Secure key exchange without transmitting the shared secret.
Disadvantages
1. Vulnerable to MITM attacks without authentication.
Conclusion
The Diffie-Hellman algorithm is a cornerstone of modern cryptography for secure key
exchange. While powerful, it must be combined with authentication mechanisms to ensure
30/43
security against MITM attacks.
2. Fixed Output Size: Hash length is fixed regardless of input size (e.g., 160 bits for SHA-1,
512 bits for SHA-512).
4. Collision Resistance: Difficult to find two different inputs with the same hash.
SHA Variants
SHA-1: Produces a 160-bit hash.
SHA-2:
31/43
Limitations of SHA
1. Collision Susceptibility:
SHA-2 improves this but may face risks from quantum computing.
2. Speed:
Faster hash functions like BLAKE and Keccak are more efficient for certain
applications.
3. Quantum Vulnerability:
SHA-1 in Detail
Key Features
Steps in SHA-1
1. Padding:
Append a '1' bit followed by enough '0' bits to make the message length congruent
to 448 modulo 512.
3. Initialize Variables:
32/43
Expand the block into 80 words (32 bits each) using a specific formula.
Use the variables and words in 80 rounds of operations, involving bitwise logical
functions, additions modulo 232 , and left rotations.
6. Output:
SHA-512 in Detail
Key Features
Steps in SHA-512
1. Padding:
Append a '1' bit followed by enough '0' bits to make the message length congruent
to 896 modulo 1024.
3. Initialize Variables:
Expand the block into 80 words (64 bits each) using a specific formula.
33/43
Additions modulo 264 .
6. Output:
Rounds 80 80
Example
SHA-1 Example
Input: "Hello"
Hash: f7c3bc1d808e04732adf679965ccc34ca7ae3441
SHA-512 Example
Input: "Hello"
34/43
Hash:
3615f80c9d293ed7402687c15deed1c1873d3451e2308c49d58c599d47c5fa12cb42ed7a584f3e
5d5177fe064b1e9c36e76fb33163dc7f97e9631a9b280685b7
Conclusion
SHA-1: Obsolete and insecure; avoid using for sensitive data.
SHA-512: A robust and secure hashing algorithm suitable for modern cryptographic
applications, including digital certificates and secure communication protocols. However,
for future-proofing against quantum threats, SHA-3 and other post-quantum algorithms
are under consideration.
35/43
you want to
create a shortcut: ")
# Take user input for the directory where the shortcut will
be created
shortcut_path = input("Enter the directory where you want
the shortcut to
be created: ")
# Take user input for the shortcut name
shortcut_name = input("Enter the name of the shortcut: ")
create_shortcut(target_file, shortcut_path, shortcut_name)
Explanation
python
import winshell
import os
os : Provides functionality to interact with the file system, such as joining paths or
retrieving directory names.
2. Function Definition
python
Parameters:
target_file : The full path of the file for which the shortcut will be created.
36/43
shortcut_path : The directory where the shortcut will be placed.
python
Combines the shortcut_path and shortcut_name with the .lnk extension to create
the full path for the shortcut.
python
link.working_directory : Sets the working directory for the shortcut to the directory
containing the target file.
37/43
python
6. Main Function
python
if __name__ == "__main__":
Ensures that the following code runs only when the script is executed directly, not when
imported as a module.
python
target_file = input("Enter the full path of the file for which you want to create a
shortcut: ")
shortcut_path = input("Enter the directory where you want the shortcut to be
created: ")
shortcut_name = input("Enter the name of the shortcut: ")
create_shortcut(target_file, shortcut_path, shortcut_name)
38/43
Execution Flow
1. The user provides the path of the target file, directory for the shortcut, and the shortcut
name.
2. The program combines the directory and shortcut name to form the .lnk path.
Output:
Notes
This program is safe for educational purposes but can be misused as part of a "virus" by
linking to malicious files.
39/43
1. NIST Digital Signature Algorithm (DSA)
The NIST Digital Signature Algorithm (DSA) is a U.S. federal standard for digital signatures,
specified in the Digital Signature Standard (DSS) by the National Institute of Standards and
Technology (NIST).
Key Features
Steps
1. Key Generation:
3. Verification:
Use Cases
40/43
The ElGamal Signature Scheme is based on the Diffie-Hellman key exchange and relies on
the discrete logarithm problem for security.
Key Features
Steps
1. Key Generation:
3. Verification:
Compute v1 = y r ⋅ rs mod p.
Compute v2 = g H(m) mod p.
If v1 = v2 , the signature is valid.
Use Cases
Key Features
41/43
Steps
1. Key Generation:
Compute s = (k − e ⋅ x) mod q .
3. Verification:
Compute r ′ = (g s ⋅ y e ) mod p.
Compute e′ = H(m∣∣r′ ) mod q .
If e′ = e, the signature is valid.
Use Cases
42/43
Conclusion
Each algorithm has its strengths and weaknesses. The choice depends on the application:
Schnorr is lightweight and efficient, making it suitable for modern applications like
blockchain.
43/43