Information & Network Security: Assignment 1 & 2 Solutions

Complete worked solutions for Information and Network Security Assignments 1 and 2, covering classical ciphers (Hill, Vigenere, Playfair, transposition, OTP) and DES internals (Feistel structure, S-boxes, CFB mode, triple DES, meet-in-the-middle attacks).

Information & Network Security: Assignment 1 & 2 Solutions
Materio
Listen
0

Assignment 1 — Classical Cryptography

1. Consider a Hill cipher with key K = "TEXT". What is the ciphertext corresponding to the plaintext "HILL"?

Convert key letters to numbers (A=0...Z=25), arranged row-wise as a 2x2 matrix:

T=19, E=4, X=23, T=19

$ K = \begin{bmatrix} 19 & 4 \\ 23 & 19 \end{bmatrix} $

Split plaintext "HILL" into digraphs: HI, LL (H=7, I=8, L=11, L=11)

For HI = [7,8]:

  • C1 = (19×7 + 4×8) mod 26 = (133+32) mod 26 = 165 mod 26 = 9 = J
  • C2 = (23×7 + 19×8) mod 26 = (161+152) mod 26 = 313 mod 26 = 1 = B

For LL = [11,11]:

  • C1 = (19×11 + 4×11) mod 26 = (209+44) mod 26 = 253 mod 26 = 19 = T
  • C2 = (23×11 + 19×11) mod 26 = (253+209) mod 26 = 462 mod 26 = 20 = U

Ciphertext = JBTU

2. Define the term information security. List and briefly define the categories of security attacks and services.

Information security protects information and information systems from unauthorized access, use, disclosure, disruption, modification, or destruction, preserving confidentiality, integrity, and availability.

Security attacks:

  • Passive attacks (observe only, hard to detect): release of message contents (eavesdropping on content), traffic analysis (studying patterns without reading content).
  • Active attacks (modify data or system behavior, easier to detect): masquerade (impersonating another entity), replay (retransmitting captured data), modification of messages, denial of service.

Security services (X.800): authentication (verifies identity), access control (prevents unauthorized resource use), confidentiality (protects against disclosure), integrity (protects against unauthorized alteration), non-repudiation (prevents denying a sent message), availability (ensures systems stay usable).

3. Using Vigenere cipher, encrypt the word 'cryptography' using the key house.

Repeat the key to match plaintext length: HOUSEHOUSEHO

Formula: Ci = (Pi + Ki) mod 26

Plain C R Y P T O G R A P H Y
Key H O U S E H O U S E H O
Sum 9 31 44 33 23 21 20 37 18 19 14 38
mod 26 9 5 18 7 23 21 20 11 18 19 14 12
Cipher J F S H X V U L S T O M

Ciphertext = JFSHXVULSTOM

4. How security of polyalphabetic cipher is improved over monoalphabetic cipher? Explain with example.

Monoalphabetic ciphers map each plaintext letter to exactly one ciphertext letter throughout the message, so the ciphertext preserves the frequency distribution of the plaintext language, making them vulnerable to frequency analysis.

Polyalphabetic ciphers (like Vigenere) shift the substitution alphabet by position/key, so the same plaintext letter can map to different ciphertext letters at different points, flattening the frequency distribution and defeating simple frequency analysis.

Example: in "cryptography" encrypted with key "house" above, the letter P appears twice (position 4 and 10) but encrypts to H and T respectively, two different letters, unlike a monoalphabetic cipher where P would always map to the same letter.

5. The encryption key in a transposition cipher is (3,2,6,1,5,4). The plain text is "We are discovered save your self". Find the decrypted text.

Key = (3,2,6,1,5,4), so the cipher uses 6 columns.

Plaintext letters only: WEAREDISCOVEREDSAVEYOURSELF (28 letters), padded to 30 with XX to complete a 5x6 grid:

$ \begin{bmatrix} W & E & A & R & E & D \\ I & S & C & O & V & E \\ R & E & D & S & A & V \\ E & Y & O & U & R & S \\ E & L & F & X & X & X \end{bmatrix} $

For encryption, columns are read out in the order given by the key (3,2,6,1,5,4). To decrypt, that process is reversed: the ciphertext is split into 6 blocks of 5 letters each, each block is written into the column indicated by the key, and once the grid is refilled, reading it row by row recovers the plaintext.

Decrypted text = "WE ARE DISCOVERED SAVE YOUR SELF"

6. Explain different type of cryptanalytic attack based on the amount of information known to the cryptanalyst.

  • Ciphertext-only attack: only ciphertext of several messages is available; the goal is to deduce plaintext or key via statistical analysis.
  • Known-plaintext attack: one or more plaintext-ciphertext pairs formed with the same key are available, used to deduce the key or decrypt other messages.
  • Chosen-plaintext attack: attacker can choose plaintext and obtain its ciphertext, allowing deliberate probing of the cipher's structure.
  • Chosen-ciphertext attack: attacker can choose ciphertext and obtain the corresponding plaintext.
  • Chosen-text attack: a combination of chosen-plaintext and chosen-ciphertext, attacker can choose either.

7. Using the playfair matrix with the key "Lieutenant" encrypt the message "nest in tree".

Build the 5x5 matrix from the deduplicated key (LIEUTENANT → L I E U T A N, J merged with I), filling remaining letters in order:

$ \begin{bmatrix} L & I & E & U & T \\ A & N & B & C & D \\ F & G & H & K & M \\ O & P & Q & R & S \\ V & W & X & Y & Z \end{bmatrix} $

Plaintext "nest in tree" → NESTINTREE. The repeated E in TREE needs a filler X inserted, giving digraphs: NE, ST, IN, TR, EX, EZ (final E padded).

Rules: same row → shift right; same column → shift down; otherwise → rectangle, swap columns.

  • NE: N(1,1), E(0,2) → rectangle → CI
  • ST: S(3,4), T(0,4) → same column → ZD
  • IN: I(0,1), N(1,1) → same column → NG
  • TR: T(0,4), R(3,3) → rectangle → US
  • EX: E(0,2), X(4,2) → same column → BE
  • EZ: E(0,2), Z(4,4) → rectangle → TX

Ciphertext = CI ZD NG US BE TX

8. Explain one time pad (OTP). What is the drawback of OTP?

The one-time pad is a symmetric technique where the key is a truly random sequence, at least as long as the plaintext, used only once and never reused, typically combined with the plaintext via XOR or modular addition. It is information-theoretically unbreakable when used correctly, since ciphertext carries no statistical link to plaintext.

Drawbacks:

  • Key must be as long as the message, impractical to generate and store for large data.
  • Secure key distribution is as hard a problem as securely sending the message itself.
  • Key can never be reused; reuse breaks the security guarantee.
  • Sender and receiver must stay perfectly synchronized on which part of the key to use.

9. Write Difference Between Stenography and Cryptography.

Aspect Steganography Cryptography
Goal Hides the existence of the message Hides the content/meaning of the message
Visibility Message is concealed within another medium, appears invisible Ciphertext is visible but unintelligible without the key
If discovered May be read directly without a key, unless also encrypted Still requires the key to be read

10. Difference between Monoalphabetic Cipher and Polyalphabetic Cipher.

Aspect Monoalphabetic Cipher Polyalphabetic Cipher
Substitution Each letter maps to one fixed ciphertext letter Substitute varies by position/key
Frequency analysis Vulnerable, preserves plaintext frequency Resistant, flattens frequency distribution
Example Caesar cipher, simple substitution Vigenere cipher, Hill cipher

Assignment 2 — DES and Block Ciphers

1. Explain internal structure of single round of DES algorithm.

Each round operates on a 64-bit block split into two 32-bit halves, Li-1 and Ri-1:

  1. Ri-1 is expanded from 32 to 48 bits using the Expansion (E) permutation.
  2. The 48-bit result is XORed with the 48-bit round key Ki.
  3. The output passes through 8 S-boxes, each taking 6 bits and outputting 4 bits, giving 32 bits total.
  4. The 32-bit S-box output goes through the P permutation.
  5. This is XORed with Li-1 to produce Ri.
  6. Li = Ri-1 (previous right half becomes new left half unchanged).

So: Li = Ri-1, Ri = Li-1 XOR F(Ri-1, Ki)

2. What is the purpose of S-boxes in DES? Explain the avalanche effect.

S-boxes: DES has 8 S-boxes, each mapping a 6-bit input to a 4-bit output via a fixed lookup table. They are the only non-linear component of DES and provide confusion, making the key-ciphertext relationship as complex as possible. Without S-boxes, DES would be linear and trivially breakable.

Avalanche effect: a small change in the input (even one bit of plaintext or key) should produce a significant, seemingly random change in the output ciphertext. DES is designed so changing one input bit flips roughly half the output bits on average, making it computationally infeasible to detect correlations between input and output changes. This is essential to resist statistical cryptanalysis.

3. Differentiate between diffusion and confusion? Explain Fiestel structure encryption and decryption.

Confusion makes the relationship between ciphertext and the encryption key as complex as possible, achieved through substitution (S-boxes).

Diffusion spreads the influence of a single plaintext bit over many ciphertext bits, achieved through permutation and mixing operations (P-box, expansion).

Feistel structure, encryption (round i):

  • Li = Ri-1
  • Ri = Li-1 XOR F(Ri-1, Ki)

Feistel structure, decryption (round i, keys applied in reverse order):

  • Ri-1 = Li
  • Li-1 = Ri XOR F(Li, Ki)

The same algorithm is used for both encryption and decryption, only the order of subkeys is reversed, so a separate decryption circuit is not needed.

4. Explain F function with diagram.

flowchart TD
    A["Ri-1 (32 bits)"] --> B["Expansion Permutation E → 48 bits"]
    B --> C["XOR with round key Ki (48 bits)"]
    C --> D["8 S-boxes: 6 bits in → 4 bits out each → 32 bits"]
    D --> E["Permutation P"]
    E --> F["Output (32 bits)"]

The Expansion step duplicates certain bits to go from 32 to 48 bits, enabling the XOR with the 48-bit key. The S-boxes provide non-linearity, and the final P permutation ensures diffusion by spreading each S-box's output bits across multiple S-boxes in the next round.

5. Explain Multiple encryption and triple DES.

Multiple encryption applies a block cipher more than once with different keys to increase effective key length, since single DES's 56-bit key is considered too short against modern hardware.

Double DES (2 encryptions) is vulnerable to the meet-in-the-middle attack, which reduces its effective security close to that of single DES, so it is not used in practice.

Triple DES (3DES) applies DES three times in Encrypt-Decrypt-Encrypt (EDE) mode:

C = Ek3(Dk2(Ek1(P)))

  • With 3 independent keys (K1, K2, K3): effective key length ~168 bits nominal, ~112 bits practical due to meet-in-the-middle attacks.
  • With 2 keys (K1 = K3): effective key length ~112 bits, backward compatible with single DES when K1 = K2 = K3.

6. Explain Cipher Feedback mode. Write advantages and disadvantages of Cipher Feedback mode.

In CFB mode, DES encrypts the previous ciphertext block (or IV for the first block), and the output is XORed with plaintext to produce ciphertext, turning a block cipher into a stream cipher.

Encryption: Ci = Pi XOR Ek(Ci-1), with C0 = IV
Decryption: Pi = Ci XOR Ek(Ci-1)

Note only the encryption function is used in both directions, never decryption.

Advantages:

  • Converts a block cipher into a self-synchronizing stream cipher, useful for streaming data.
  • Errors in one ciphertext block affect only that block and the next during decryption.
  • No need to pad plaintext to a multiple of block size.

Disadvantages:

  • Encryption cannot be parallelized, since each block depends on the previous ciphertext.
  • A bit error in transmitted ciphertext corrupts the current block completely and causes one bit of error in the next block.

7. Difference between block cipher and stream cipher.

Aspect Block Cipher Stream Cipher
Unit of encryption Fixed-size blocks (e.g. 64/128 bits) Bit-by-bit or byte-by-byte
Speed Generally slower Generally faster, real-time friendly
Examples DES, AES, Blowfish RC4, A5/1

8. Explain Meet in the Middle Attack.

The meet-in-the-middle (MITM) attack targets multiple encryption schemes (like Double DES) by computing encryption and decryption independently from both ends and matching in the middle, instead of brute-forcing the full combined key space.

For Double DES: C = Ek2(Ek1(P))

Given a known plaintext-ciphertext pair (P, C):

  1. Compute X = Ek1(P) for every possible value of K1, and store all these results in a table.
  2. Compute X = Dk2(C) for every possible value of K2, checking each against the stored table.
  3. Any matching X value gives a candidate (K1, K2) pair.

This reduces attack complexity from O(2^112) (brute force over both keys) to roughly O(2^56) time and O(2^56) storage, close to the cost of breaking single DES, which is why Double DES offers little practical security benefit over single DES.

9. Explain Tripple DES With 2 Keys and 3 Keys.

3DES with 2 keys (K1, K2, K1):

C = Ek1(Dk2(Ek1(P)))

Effective key length ~112 bits. Backward compatible with single DES if K1 = K2.

3DES with 3 keys (K1, K2, K3):

C = Ek3(Dk2(Ek1(P)))

Effective key length ~168 bits nominal, ~112 bits practical against meet-in-the-middle attacks. Highest security among 3DES variants at the cost of managing three independent keys.

10. Explain Meet in the Middle Attack in 2DES.

Double DES (2DES): C = Ek2(Ek1(P))

Given a known plaintext-ciphertext pair (P, C):

  1. Compute A = Ek1(P) for all 2^56 possible values of K1, and store each (K1, A) pair in a table sorted by A.
  2. Compute B = Dk2(C) for all 2^56 possible values of K2.
  3. For each B, look up whether it matches any A already in the table.
  4. Any match gives a candidate key pair (K1, K2); verify it against a second known plaintext-ciphertext pair to eliminate false positives, since a single match could occur by chance.

This attack requires roughly 2^56 time for each phase (2^57 total) and about 2^56 storage, far less than the naive 2^112 brute-force complexity Double DES was intended to provide. This is exactly why Double DES is not considered secure in practice, and why Triple DES (3 applications, not 2) is used instead.