SE205 - Unit 2: Cryptography (Symmetric Ciphers)

Glossary of Terms

A symmetric-key block cipher that applies the Data Encryption Standard (DES) algorithm three times to each data block (Encrypt-Decrypt-Encrypt sequence). Developed to improve DES security with a longer effective key length.

A symmetric-key block cipher standard adopted by the U.S. government. It uses key sizes of 128, 192, or 256 bits and encrypts data in 128-bit blocks through multiple rounds (10, 12, or 14 respectively). Widely used and considered very secure.

A type of cryptography that uses two separate but mathematically related keys: a public key (for encryption) and a private key (for decryption). Also known as public-key cryptography.

An encryption algorithm that processes input data in fixed-size blocks (e.g., 64-bit or 128-bit blocks) at a time, producing an output block for each input block. Examples: DES, AES, 3DES.

A cryptanalytic attack that involves trying every possible key on a piece of ciphertext until an intelligible plaintext is obtained. Feasibility depends on key space size.

A simple substitution cipher where each letter in the plaintext is shifted a certain fixed number of positions down the alphabet. Example: Shift 3 (A becomes D, B becomes E).

The algorithm used for transforming plaintext into ciphertext (encryption) and back (decryption).

The scrambled, unreadable message resulting from applying an encryption algorithm (cipher) to plaintext.

Older methods of encryption, typically operating on characters, including substitution and transposition techniques. Examples: Caesar, Playfair, Hill, Rail Fence.

The study and practice of analyzing information systems to understand hidden aspects, often focusing on finding weaknesses in cryptographic algorithms or breaking ciphers without knowing the key.

The science and study of techniques for secure communication in the presence of third parties (adversaries). Involves encryption, decryption, key management, etc.

The process of converting ciphertext back into its original plaintext form using a key and a decryption algorithm.

An outdated symmetric-key block cipher standard, officially retired in 2005. It uses a 56-bit effective key and operates on 64-bit blocks through 16 rounds of permutation and substitution.

The process of converting plaintext into ciphertext using a key and an encryption algorithm to make it unreadable to unauthorized parties.

A polygraphic substitution cipher based on linear algebra. It uses a matrix key to encrypt blocks of letters.

A piece of information (parameter) used by a cipher algorithm to transform plaintext into ciphertext or vice versa. In symmetric crypto, the same key is used for both; in asymmetric, different but related keys are used.

A substitution cipher where the cipher alphabet is fixed throughout the encryption process (each plaintext letter always maps to the same ciphertext letter). Vulnerable to frequency analysis.

The original, readable message or data before encryption.

A manual symmetric encryption technique that encrypts pairs of letters (digraphs), instead of single letters. It uses a 5x5 grid based on a keyword.

A substitution cipher that uses multiple substitution alphabets (e.g., based on a keyword), making it more resistant to frequency analysis than monoalphabetic ciphers. Example: Vigenère cipher.

A simple transposition cipher where plaintext is written downwards diagonally on successive "rails" of an imaginary fence and then read off as sequences of rows.

An educational simplified version of the DES algorithm, operating on 8-bit blocks with a 10-bit key and involving 2 rounds. Used to illustrate the principles of block ciphers.

An encryption algorithm that processes input data continuously, typically one bit or one byte at a time, producing one output element for each input element. Example: XOR cipher.

A method of encryption where units of plaintext (like letters or bits) are replaced with ciphertext units according to a defined system (the key).

A type of cryptography where the same secret key is used for both encryption and decryption. Requires secure key distribution.

A method of encryption where the positions of plaintext units (like letters) are shifted according to a regular system, rearranging the order but keeping the letters themselves unchanged.

A simple stream cipher technique where the plaintext is combined with a key using the bitwise XOR operation. Repeating the XOR operation with the same key decrypts the ciphertext.

Key Concepts & Examples from Unit 2

Cryptography Fundamentals

Cryptography is the study of secure communication techniques.

  • Dimensions of Classification:
    1. Type of Operations: Substitution (replace elements) or Transposition (rearrange elements).
    2. Number of Keys: Symmetric (one shared key) or Asymmetric (public/private key pair).
    3. Way Plaintext is Processed: Block Cipher (process fixed-size blocks) or Stream Cipher (process continuously).
  • Basic Terms: Plaintext (original), Ciphertext (coded), Cipher (algorithm), Key (secret parameter), Encrypt (plaintext to ciphertext), Decrypt (ciphertext to plaintext).
  • Symmetric Model: Uses a single shared secret key K. Encryption: Y = E(K, X). Decryption: X = D(K, Y). Requires secure key distribution.

Cryptanalysis

The study of breaking ciphers. Main approaches:

  • Cryptanalytic Attack: Exploits algorithm characteristics, possibly using known plaintext/ciphertext pairs.
  • Brute-Force Attack: Tries every possible key. Feasibility depends on key length (key space size). Longer keys make this harder.

Classical Encryption Techniques (Character-Oriented)

1. Substitution Techniques

Replace plaintext letters with other letters, numbers, or symbols.

Caesar Cipher

Shift each letter by a fixed amount (key k).

Encryption: C = (p + k) mod 26

Decryption: P = (C - k) mod 26

Example: Encrypt "HELLO" with key k=10.

Map letters to numbers (A=0, B=1,... Z=25): H=7, E=4, L=11, L=11, O=14.

Apply formula:

  • (7 + 10) mod 26 = 17 -> R
  • (4 + 10) mod 26 = 14 -> O
  • (11 + 10) mod 26 = 21 -> V
  • (11 + 10) mod 26 = 21 -> V
  • (14 + 10) mod 26 = 24 -> Y
Ciphertext: ROVVY

Python Code (Caesar Encrypt):

#enter the word to encrypt
text = "hello world"
#define the shift
shift = 4
def ceaser (message, offset): #messages to encrypt, offset to shift
    alphapet = 'abcdefghijklmnopqrstuvwxyz'
    enc_text = ''
    for char in message.lower (): # convert every letter to its small phase
        if char == " ": #dealing with spaces
            enc_text += char # add it without changes
        else:
            try: # Handle non-alphabetic chars if needed
                index = alphapet.find(char)
                new_index = (index + offset) % len(alphapet) # new letter index, len to range 0-25
                enc_text += alphapet[new_index] #Shifted letter
            except ValueError:
                 enc_text += char # Keep non-alpha chars as is
    return enc_text

encrypted = ceaser(text, shift)
print ('plain text :', text)
print ('encrypted text :', encrypted)
# Assignment 1: write a code that decrypt any given message based of Caesar chipper.
# Hint: Decryption is encryption with shift = (26 - k)
                    
Monoalphabetic Cipher

Each plaintext letter maps to a unique, fixed ciphertext letter (e.g., A->J, B->I, C->B...). Uses a fixed substitution alphabet (26! possible keys).

Example: Plaintext "CRYPTOGRAPHY", Substitution: A->J, B->I, C->B, ..., R->S, Y->E, etc.

(Using the specific table from slide 22: C->B, R->S, Y->E, P->U, T->W, O->A, G->C, R->S, A->J, P->U, H->N, Y->E)

Ciphertext (using slide 22 table): BSEZ WUC SJZN E

Note: The example calculation differs slightly from the slide's result, double-checking the specific substitutions is needed for exact match. The slide result was BSEZWUCSJZNE. Let's re-check: C->B, R->S, Y->E, P->U, T->W, O->A, G->C, R->S, A->J, P->U, H->N, Y->E. This still seems different. Let's use the slide's result as the intended example.

Ciphertext (as per slide 22): BSEZWUCSJZNE

Vulnerable to frequency analysis.

Polyalphabetic Cipher

Uses multiple substitution alphabets, often determined by a keyword. Each occurrence of a character can map to a different character.

Example: Plaintext "SECURITY", Key: Shift 1st letter by 3, 2nd by 5, 3rd by 7 (repeating pattern).

Map letters to numbers (A=0..Z=25): S=18, E=4, C=2, U=20, R=17, I=8, T=19, Y=24

Apply shifts (3, 5, 7, 3, 5, 7, 3, 5):

  • S (18) + 3 = 21 -> V
  • E (4) + 5 = 9 -> J
  • C (2) + 7 = 9 -> J
  • U (20) + 3 = 23 -> X
  • R (17) + 5 = 22 -> W
  • I (8) + 7 = 15 -> P
  • T (19) + 3 = 22 -> W
  • Y (24) + 5 = 29 mod 26 = 3 -> D
Ciphertext: VJJXWPWD
Playfair Cipher

Encrypts digraphs (pairs of letters) using a 5x5 grid based on a keyword (I/J often share a cell).

Example: Keyword "MONARCHY", Plaintext "BALLON".

1. Create 5x5 Grid (Fill keyword letters first, omit duplicates, then fill remaining alphabet):

MONAR
CHYBD
EFGI/JK
LPQST
UVWXZ

2. Prepare Plaintext: Split into digraphs. If double letter, insert filler (e.g., 'X'). If odd length, append filler. "BALLON" -> BA LX LO NX (Assuming X filler for LL, and for odd length if needed - here ON doesn't need it).

3. Encrypt Digraphs using grid rules:

  • BA: Same row (Row 2). Replace with letter to the right (wrap around). B->D, A->R? Re-checking slide example: slide used different rules/grid? Slide says BA->IB. Let's follow slide's rules based on output. Rule 1 (Same Column): Shift down. Rule 2 (Same Row): Shift right. Rule 3 (Rectangle): Use opposite corners on same row.
  • BA -> IB (Rectangle rule: B(2,4), A(1,4). Corners are I(3,4), R(1,1)? No, I(3,4) and C(2,1)? Still doesn't match. Let's use slide result directly.) BA -> IB (Implies B and A are rectangle corners, replaced by I and B? Check grid: A(1,4), B(2,4). Same column! Shift down: A->S, B->D? Still no match. There might be an error in the slide example or a specific Playfair variant used.) Using slide's result: BA -> IB
  • LX: Rectangle L(4,1), X(5,4). Corners are U(5,1), T(4,4)? Slide says: LX -> SU (Implies corners are S and U. Let's assume these are the rules.)
  • LO: Same row (Row 4). Shift right. L->P, O->? O is row 1. This pair isn't in same row. Rectangle L(4,1), O(1,2). Corners are M(1,1) P(4,2)? Slide says: LO -> PM.
  • ON: Rectangle O(1,2), N(1,3). Same row! Shift right. O->N, N->A. Slide says: ON -> NA. (This one matches the rule!)

Conclusion: The Playfair example on the slide seems inconsistent with standard rules or uses a different grid/rule interpretation for some pairs. Following the slide's provided transformations:

Ciphertext (based on slide transformations): IBSUPMNA
Hill Cipher

Uses matrix multiplication for encryption. Key is an invertible matrix.

Encryption: C = P * K mod 26

Decryption: P = C * K-1 mod 26

Example: Plaintext "HATS", Key K = [[3, 3], [2, 5]].

Map letters: H=7, A=0, T=19, S=18.

Process digraphs: HA = [7, 0], TS = [19, 18].

Encrypt HA:

[7, 0] * [[3, 3], [2, 5]] mod 26
= [(7*3 + 0*2), (7*3 + 0*5)] mod 26
= [21, 21] mod 26
= [21, 21] -> VV (V=21)

Correction: Slide shows HA -> VO. Let's recheck slide calculation:

HA: [7 0] * K = [(7*3 + 0*2) (7*3 + 0*5)] mod 26 = [21 21] mod 26 -> VV.

TS: [19 18] * K = [(19*3 + 18*2) (19*3 + 18*5)] mod 26 = [ (57+36) (57+90) ] mod 26 = [93 147] mod 26.

93 mod 26 = 15 (P)

147 mod 26 = 17 (R)

Result: VVPR. Slide shows VOHY. Let's check slide's calculation steps.

Slide HA calc: [(7*3 + 0*3) (7*2 + 0*5)] mod 26 = [21 14] mod 26 -> VO. Ah, the matrix multiplication order/setup in the slide seems different (applying key columns?). Or maybe P is represented as column vector? Let's assume slide uses P as column vector [P1 P2]^T, so C = K * P.

HA (H=7, A=0): K * [7 0]^T = [[3, 3], [2, 5]] * [7 0]^T = [ (3*7+3*0) (2*7+5*0) ]^T mod 26 = [21 14]^T mod 26 -> VO (Matches slide)

TS (T=19, S=18): K * [19 18]^T = [[3, 3], [2, 5]] * [19 18]^T = [ (3*19+3*18) (2*19+5*18) ]^T mod 26 = [ (57+54) (38+90) ]^T mod 26 = [111 128]^T mod 26.

111 mod 26 = 7 (H)

128 mod 26 = 24 (Y)

Result: HY (Matches slide calculation for TS)

Ciphertext (following slide's matrix multiplication method): VOHY

2. Transposition Techniques

Rearrange the letters of the plaintext without changing the letters themselves.

Rail Fence Cipher

Write plaintext diagonally on 'rails' and read off row by row.

Example: Plaintext "meet me after the party", Depth (rails) = 2.

Write on rails:

m . e . m . a . t . r . h . p . r . y
. e . t . m . e . f . e . t . e . a . t

Read Row 1: mematrhpry

Read Row 2: etmefeteat

Correction: Slide example shows different spacing/result. Let's follow slide.

Slide method:

m e m a t r h p r y
e t e f e t e a t

Read Row 1: mematrhpry

Read Row 2: etefeteat

Ciphertext: mematrhpryetefeteat

Simple Modern Encryption (Bit-Oriented)

XOR Cipher (Stream Cipher)

Combines plaintext bits with key bits using XOR.

Cipher = Plaintext XOR Key

Plaintext = Cipher XOR Key

(XOR: 0^0=0, 0^1=1, 1^0=1, 1^1=0)

Example: Encrypt M = 1110101010, Key K = 1100110101.

   1110101010 (Plaintext)
XOR 1100110101 (Key)
------------------
   0010011111 (Ciphertext)
                         
Ciphertext: 0010011111

Modern Round Ciphers (Block Ciphers)

Operate on fixed-size blocks using multiple rounds of substitution and permutation.

DES (Data Encryption Standard)

  • Outdated symmetric key block cipher (retired 2005).
  • Key: 64 bits (56 effective + 8 parity).
  • Block Size: 64 bits.
  • Rounds: 16 rounds of substitution and permutation.
  • Structure: Initial Permutation, 16 rounds using subkeys generated from the main key, Final Permutation.
  • Considered insecure due to short key length (vulnerable to brute-force).

SDES (Simplified DES) - Educational

  • Simplified version for teaching.
  • Key: 10 bits.
  • Block Size: 8 bits.
  • Rounds: 2.
  • Process involves: Initial Permutation (IP), Round function (fk) involving Expansion/Permutation (E/P), Key XOR, S-Boxes, P4 permutation, Switch (SW) halves, Round function (fk) with second subkey, Inverse Initial Permutation (IP-1).
  • Key Generation: P10 permute -> Split 5 bits + 5 bits -> LS-1 (Left Shift 1) on each half -> P8 permute (yields K1) -> LS-2 (Left Shift 2) on halves from after LS-1 -> P8 permute (yields K2).

SDES Example Walkthrough (Key Gen & Encrypt from slides 34-44):

Given: Plaintext M=00101000, Key=1100011110, IP=[2 6 3 1 4 8 5 7], P10=[3 5 2 7 4 10 1 9 8 6], P8=[6 3 7 4 8 5 10 9], E/P=[4 1 2 3 2 3 4 1], S0=[[1,0,3,2],[3,2,1,0],[0,2,1,3],[3,1,3,2]], S1=[[0,1,2,3],[2,0,1,3],[3,0,1,0],[2,1,0,3]], P4=[2 4 3 1], IP-1=[4 1 3 5 7 2 8 6]

1. Key Generation:

  • Key = 11000 11110
  • P10(Key) = 00110 01111 (Applying P10 indices: 3rd=0, 5th=0, 2nd=1, 7th=1, 4th=0 | 10th=0, 1st=1, 9th=1, 8th=1, 6th=1) -> 00110 01111
  • Split: Left=00110, Right=01111
  • LS-1: Left=01100, Right=11110
  • Combine: 0110011110
  • P8(Combined LS-1): K1 = 11100111 (Applying P8 indices: 6th=1, 3rd=1, 7th=1, 4th=0 | 8th=1, 5th=0, 10th=0, 9th=1) -> 1110 0111 (Slide shows K1=11101001, slide 37 shows K1=11101001 - checking slide 37 P8 calculation: Key=1100011110 -> P10=0011001111 -> LS1=0110011110 -> P8(0110011110) = 11101001. Let's use this.) K1 = 11101001
  • Halves after LS-1: Left=01100, Right=11110
  • LS-2: Left=10001, Right=11011 (Shift by 2)
  • Combine: 1000111011
  • P8(Combined LS-2): K2 = 10100111 (Applying P8: 6th=1, 3rd=0, 7th=1, 4th=0 | 8th=0, 5th=1, 10th=1, 9th=1) -> 1010 0111. K2 = 10100111 (Matches slide 37)

2. Encryption: M=00101000

  • IP(M): 00100010 (Applying IP indices: 2nd=0, 6th=0, 3rd=1, 1st=0 | 4th=0, 8th=0, 5th=1, 7th=0) -> 0010 0010
  • Split: L0=0010, R0=0010
  • Round 1 (fK1): Use R0=0010, K1=11101001
    • E/P(R0) = 0100 0010 (Applying E/P indices: 4th=0, 1st=0, 2nd=0, 3rd=1 -> 0001; 2nd=0, 3rd=1, 4th=0, 1st=0 -> 0100) -> 0001 0100 (Slide 40 shows E/P(0010)=00010100. Let's use slide result.) E/P(R0) = 0001 0100
    • E/P(R0) XOR K1 = 00010100 XOR 11101001 = 11111101
    • S-Box Input: Left=1111, Right=1101
    • S0(1111): Row=(11)2=3, Col=(11)2=3. S0[3][3]=2=(10)2
    • S1(1101): Row=(11)2=3, Col=(10)2=2. S1[3][2]=0=(00)2
    • Combine S-Box output: 1000
    • P4(1000) = 0001 (Applying P4 indices: 2nd=0, 4th=0, 3rd=0, 1st=1) -> 0001
    • Result F = 0001
  • L1 = L0 XOR F = 0010 XOR 0001 = 0011
  • R1 = R0 = 0010
  • Switch (SW): Input to Round 2 is L=0010, R=0011
  • Round 2 (fK2): Use R=0011, K2=10100111
    • E/P(R) = 1001 0110 (Apply E/P to 0011: 4th=1, 1st=0, 2nd=0, 3rd=1 -> 1001; 2nd=0, 3rd=1, 4th=1, 1st=0 -> 0110) -> 1001 0110
    • E/P(R) XOR K2 = 10010110 XOR 10100111 = 00110001
    • S-Box Input: Left=0011, Right=0001
    • S0(0011): Row=(01)2=1, Col=(01)2=1. S0[1][1]=2=(10)2
    • S1(0001): Row=(01)2=1, Col=(00)2=0. S1[1][0]=2=(10)2 (Check S1 Table: S1[1][0]=2. Correct)
    • Combine S-Box output: 1010
    • P4(1010) = 0011 (Applying P4: 2nd=0, 4th=0, 3rd=1, 1st=1) -> 0011
    • Result F = 0011
  • L2 = L(from SW) XOR F = 0010 XOR 0011 = 0001
  • R2 = R(from SW) = 0011
  • Combine: L2 R2 = 0001 0011
  • IP-1(00010011) = 10001010 (Applying IP-1: 4th=1, 1st=0, 3rd=0, 5th=0 | 7th=1, 2nd=0, 8th=1, 6th=0) -> 1000 1010
Final Ciphertext: 10001010 (Slide 44 shows 10001010. Matches!)

3DES (Triple DES)

  • Applies DES three times: Encrypt(K1) -> Decrypt(K2) -> Encrypt(K3).
  • Modes:
    • 3-Key 3DES: K1, K2, K3 are independent (Strongest, 168-bit effective key).
    • 2-Key 3DES: K1 = K3, K2 is different (112-bit effective key, still common).
  • Provides backward compatibility with DES (if K1=K2=K3).
  • Slower than AES but still used.

AES (Advanced Encryption Standard)

  • Current standard, widely used (SSL/TLS, VPNs, file encryption).
  • Symmetric block cipher.
  • Block Size: 128 bits.
  • Key Sizes: 128, 192, or 256 bits.
  • Rounds: 10 (for 128-bit key), 12 (for 192), 14 (for 256).
  • Structure: Not a Feistel cipher like DES. Operates on a 4x4 byte matrix (State).
  • Round Operations:
    1. SubBytes: Non-linear byte substitution using an S-box.
    2. ShiftRows: Cyclically shifts bytes within rows of the State matrix.
    3. MixColumns: Mixes bytes within columns using matrix multiplication in Galois Field GF(28). (Omitted in final round).
    4. AddRoundKey: XORs the State with a round key derived from the main key.
  • Initial AddRoundKey before first round.
  • Considered secure and efficient.

Fill in the Blank Questions

True/False Questions

Multiple Choice Questions