CACS459 Information Security

Information SecurityUnit 311 min read

Symmetric Key Cryptography: Algorithms, Feistel, Playfair & Vernam

Unit 3 of Information Security covers core symmetric-key cryptography: how secret-key algorithms like DES, AES, Playfair, and Vernam work, their mathematical foundations, and real-world trade-offs between speed and security. Includes key scheduling, confusion/diffusion, and practical encryption/decryption workflows wit

TAKEAWAYS:

  • Symmetric-key algorithms use a single shared key for encryption/decryption, offering speed but requiring secure key distribution.
  • Feistel networks (used in DES) split blocks into halves, apply functions, and swap halves iteratively to achieve confusion and diffusion.
  • Playfair cipher handles digraphs (2-letter blocks) with a 5×5 matrix, while Vernam cipher (one-time pad) is theoretically unbreakable but impractical for reuse.
  • AES uses substitution-permutation networks with 10–14 rounds, where each round applies key mixing, byte substitution, row shifting, and column mixing.
  • Confusion (hiding key statistics) and diffusion (spreading plaintext influence) are critical for security in block ciphers.
  • Real-world systems (e.g., eSewa’s payment tokens, Khalti’s session keys) rely on symmetric encryption for speed, often combined with asymmetric keys for initial handshakes.

Core Concepts: Symmetric Key Cryptography

Symmetric-key cryptography is the oldest and fastest form of encryption, where the same key is used for both encryption and decryption. Unlike asymmetric cryptography (Unit 4), it does not rely on complex mathematical operations like RSA, making it 100–10,000× faster but requiring secure key exchange.

Why Symmetric Keys?

  • Speed: Ideal for encrypting large data (e.g., files, databases).
  • Efficiency: Used in protocols like TLS (HTTPS), Wi-Fi (WPA2), and disk encryption (BitLocker).
  • Limitation: Key distribution is the biggest challenge (e.g., how does Alice send Bob a secret key without eavesdroppers intercepting it?).

1. Stream Ciphers vs. Block Ciphers

Feature Stream Cipher Block Cipher
Operation Encrypts one bit/byte at a time Encrypts fixed-size blocks (e.g., 64-bit, 128-bit)
Key Reuse Never reuse keys (Vernam cipher) Keys can be reused for same block size
Speed Faster (hardware-friendly) Slower (software overhead)
Security Vulnerable if keystream reused Resistant if designed well (e.g., AES)
Examples Vernam cipher, RC4 (deprecated) DES, AES, 3DES, Blowfish

2. Feistel Structure: The Backbone of DES

The Data Encryption Standard (DES) uses a 16-round Feistel network to encrypt 64-bit blocks with a 56-bit key. The structure ensures confusion (key dependency) and diffusion (plaintext spreading).

→ f(R0, K1) → R1L0 (32-bit)→ L1 = R0R0 (32-bit)Initial Permutationf(R0, K1) = E(R0) ⊕ K1 → S-boxes → P-box → R1→ L2 = R1L1 = R0Round 1DES Feistel Network
DES Feistel network: initial split and first round

How Feistel Works (Step-by-Step)

  1. Split the block: Divide the 64-bit input into left (L₀) and right (R₀) halves.
  2. Round function:
    • Compute Lᵢ = Rᵢ₋₁ (swap halves).
    • Compute Rᵢ = Lᵢ₋₁ ⊕ f(Rᵢ₋₁, Kᵢ) (XOR with a function of the right half and round key).
  3. Repeat 16 times: Each round uses a subkey derived from the main key via key scheduling.
stateDiagram-v2
    [*] --> L0: L0 (32 bits)
    [*] --> R0: R0 (32 bits)
    L0 --> F1: f(R0, K1)
    R0 --> L1: R0
    F1 --> R1: L0 XOR f(R0, K1)
    L1 --> F2: f(R1, K2)
    R1 --> L2: R1
    F2 --> R2: L1 XOR f(R1, K2)
    Note right of R2: ... (16 rounds)
    L16 --> Output: L16 || R16
    Note right of [*]: "Initial split: L0 = left half, R0 = right half"
    Note right of F1: "f(Rᵢ₋₁, Kᵢ) = round function (e.g., DES f)"

Key Schedule in DES

DES uses permutation and compression to generate 16 subkeys:

  1. Permute the 56-bit key using PC-1 (permutation choice).
  2. Split into C₀ (28 bits) and D₀ (28 bits).
  3. Left-shift C and D by 1 or 2 bits (alternating per round).
  4. Compress using PC-2 to get a 48-bit round key.

Example: For a key 10110011010001010101001101010011 (56 bits):

  • After PC-1: 11010010100010101010011010100110 (56 bits).
  • Split into C₀ = 1101001010001010, D₀ = 1010101001101010.
  • After 1st left-shift (1 bit): C₁ = 1010010100010101, D₁ = 0101010011010100.
  • PC-2 compresses to a 48-bit subkey.

3. Playfair Cipher: Digraph-Based Encryption

The Playfair cipher (1854) encrypts pairs of letters (digraphs) using a 5×5 matrix. It’s not secure by modern standards but teaches confusion and substitution.

How Playfair Works

  1. Create the matrix:
    • Fill with letters (A-Z, excluding J), skipping duplicates.
    • Example key: PLAYFAIREXAMPLE → Matrix:
      P L A Y F
      R E X M B
      C D G H I
      K N O Q S
      T U V W Z
      
  2. Encrypt digraphs:
    • If both letters are in the same row, replace each with the next letter in the row (wrapping around).
    • If in the same column, replace each with the next letter in the column.
    • If in a rectangle, replace each with the letter in its row and the other’s column.

Example: Encrypt PLAY with key PLAYFAIREXAMPLE:

  • P L → Same row → R A.
  • A Y → Rectangle → F L.
  • Ciphertext: RAFL.
Plaintext DigraphsP LEncrypted DigraphsR A
Playfair cipher: plaintext digraphs (left) → ciphertext digraphs (right) via key matrix

4. Vernam Cipher: The One-Time Pad

The Vernam cipher (1917) is a stream cipher that combines plaintext with a true random key using XOR. It is provably secure if:

  • The key is truly random.
  • The key is as long as the plaintext.
  • The key is never reused.

How Vernam Works

  1. Convert plaintext and key to binary.
  2. XOR each bit: C = P ⊕ K.
  3. Decrypt by XORing ciphertext with the same key: P = C ⊕ K.

Example:

  • Plaintext: HELLO (ASCII: 01001000 01000101 01001100 01001100 01001111)
  • Key: XORKEY (ASCII: 01011000 01001111 01010010 01001101 01001110)
  • Ciphertext: 49 4A 22 25 27 (hex).

Limitation: Requires a new key for every message (impractical for most uses).


5. Advanced Encryption Standard (AES)

AES is the modern standard (2001), replacing DES. It uses substitution-permutation networks with 10–14 rounds (depending on key size: 128, 192, or 256 bits).

AES Key Schedule

  1. Key expansion:
    • 128-bit key → 176 bytes (14 rounds).
    • Uses Rcon (round constants) and S-box (substitution box).
  2. Round transformations (per block):
    • SubBytes: Non-linear substitution via S-box.
    • ShiftRows: Shift rows cyclically.
    • MixColumns: Linear mixing of columns.
    • AddRoundKey: XOR with round key.
flowchart TD
    A["Plaintext Block"] --> B["AddRoundKey"]
    B --> C["SubBytes: S-box substitution"]
    C --> D["ShiftRows: cyclic row shifts"]
    D --> E["MixColumns: column mixing"]
    E --> F["AddRoundKey"]
    F --> G["Next Round"]
    G -->|"10-13 rounds"| E
    E --> H["Final Round: SubBytes → ShiftRows → AddRoundKey"]
    H --> I["Ciphertext"]

Example: AES-128 encrypts a 16-byte block with 10 rounds. The first round key is derived by:

  1. Copy the original key.
  2. Apply Rcon[1] to the first word.
  3. Substitute bytes and mix columns for subsequent words.

6. Confusion vs. Diffusion

Property Confusion Diffusion
Goal Hide relationship between key and ciphertext Spread plaintext statistics across ciphertext
Method Non-linear operations (S-boxes) Linear mixing (permutations, XOR)
Example DES’s S-boxes AES’s ShiftRows + MixColumns
Result Hard to deduce key from ciphertext Small plaintext changes → large ciphertext changes
016324863Confusion32 bitsDiffusion32 bits
Confusion vs. diffusion: how AES achieves security

Real-world tie-in:

  • eSewa’s payment tokens use AES for confusion (hiding transaction details) and diffusion (so altering one digit changes the entire token).
  • Khalti’s session keys rely on AES to ensure that even a single bit flip in the key drastically changes the encrypted session data.

7. Worked Example: Playfair Encryption for "SECRET"

Key: MONARCHY Matrix:

M O N A R
C H Y B D
E F G I K
L P Q S T
U V W X Z

Steps:

  1. Split SECRET into digraphs: SE CR ET (insert X for odd length: SE CR EX T).
  2. Encrypt:
    • S E → Rectangle → O M.
    • C R → Same row → D U.
    • E X → Rectangle → G V.
    • T → Pad with Z → T Z → Same column → S L.
  3. Ciphertext: OM DUGV SL.

In the Real World

  1. eSewa’s Payment Security:

    • Uses AES-256 for confusion and diffusion when encrypting transaction data.
    • The key schedule ensures that even if an attacker captures ciphertext, they cannot reverse-engineer the original payment details without the key.
  2. Khalti’s Session Tokens:

    • After login, Khalti generates a symmetric session key (e.g., AES-128) to encrypt all subsequent API calls.
    • The Feistel-like structure in TLS (used by Khalti) ensures that session keys are resistant to brute-force attacks.
  3. NTC’s Network Encryption:

    • Nepal Telecom uses AES in CBC mode to secure VoIP calls, where each block’s encryption depends on the previous ciphertext (initialization vector, IV) to prevent patterns.
    • Diffusion ensures that a single bit error in transmission doesn’t corrupt the entire call.
  4. Bank Loan Interest Calculations (Vernam Analogy):

    • While banks don’t use Vernam for loans, the principle of one-time keys is analogous to unique transaction IDs in online banking.
    • Example: If a bank sends a loan approval code, it might use a one-time AES key for that specific transaction, ensuring replay attacks fail.

Exam Tip: How to Score Full Marks

  1. Diagrams are mandatory:

    • For Feistel structure, draw the 16-round diagram with L/R splits and XOR gates.
    • For AES, show the round transformations (SubBytes → ShiftRows → MixColumns).
    • For Playfair, include the 5×5 matrix and digraph encryption steps.
  2. Key terms to define:

    • Confusion: "Hiding the relationship between key and ciphertext."
    • Diffusion: "Disseminating the influence of plaintext statistics."
    • Feistel network: "A structure where each round swaps halves and applies a function."
  3. Worked examples:

    • DES key schedule: Show PC-1, left-shifts, and PC-2 for a given key.
    • Playfair: Always show the matrix construction and digraph encryption steps.
    • AES: Trace one round for a 4×4 state matrix.
  4. Common pitfalls:

    • Vernam cipher: Never reuse keys—examiners check for this!
    • Feistel: Remember that Lᵢ = Rᵢ₋₁ (swap happens after XOR).
    • AES: The last round skips MixColumns.
  5. Comparison tables:

    • Always compare stream vs. block ciphers, DES vs. AES, or Playfair vs. Vernam in a structured table.

Based on the TU BCA syllabus for Information Security (CACS459), unit 3.

Discussion

Loading…