Chapter 2 - Symmetric Encryption

Updated 4 Oct 2026

ไปทวนเรื่องของ Definition มาให้ดี ๆ

What is Cryptography?

Definitions

  • American Heritage Dictionary:
    • "The art or process of writing in or deciphering secret code"
    • deciphering ≠ enciphering
  • Webster Dictionary:
    • "The science or study the techniques of secret writing"
  • Technical Definition:
    • A way to transform data into an unintelligible form
    • The process is reversible with no data loss
    • Usually one-to-one mapping: plaintext ↔encryption/decryption\xleftrightarrow{\text{encryption/decryption}} ciphertext

Think of cryptography like a lockbox: you put your message in, lock it with a key, and only someone with the right key can unlock and read it.

Cryptology Branches

Cryptology: The study of techniques for ensuring the secrecy and authenticity of information

Two main branches:

  1. Cryptography (ศาสตร์การเข้ารหัส):
    • Study of how to design encryption algorithms
  2. Cryptanalysis:
    • Study of how to break encryption algorithms

Cryptography Purpose

  • A study of encryption algorithms used for encrypting and decrypting messages
  • Allows users to transmit secret information (ciphertext) over unsecured networks

The Encryption Process

  • Encryption = Key + Algorithm
Plaintext → [Encryption] → Ciphertext → [Decryption] → Plaintext
                ↑                           ↑
           Shared secret key        Shared secret key

The encryption process is like sending a locked safe through the mail - even if someone intercepts it, they can't open it without the key.


Cryptography Terminology

Key Terms

  • Plaintext: Message in a clear form that can be read
  • Ciphertext: Message in an unreadable form
  • Encryption: Changing plaintext to ciphertext
  • Decryption: Changing ciphertext back to plaintext
         ┌─────────┐
         │Plaintext│
         └────┬────┘
              │
         ┌────▼────┐         ┌─────┐
         │ Encrypt │◄────────│ key │
         └────┬────┘         └─────┘
              │                 │
         ┌────▼────┐            │
         │CipherTxt│            │
         └────┬────┘            │
              │              ┌──▼──┐
         ┌────▼────┐         │ key │
         │ Decrypt │◄────────┴─────┘
         └────┬────┘
              │
         ┌────▼────┐
         │Plaintext│
         └─────────┘

Secret Writing Examples

Example 1: Hidden Message in Appraisal

The HR manager received this appraisal report:

  1. "Bob, my assistant programmer, can always be found
  2. working hard at his desk. He works independently, without
  3. wasting company time talking to colleagues. Bob never
  4. thinks twice about helping fellow employees, and always
  5. finishes given assignments on time. Often he takes extended
  6. measures to complete his work, sometimes skipping coffee
  7. breaks. Bob is a dedicated individual who has absolutely no
  8. vanity in spite of his high accomplishments and profound
  9. knowledge in his field. I firmly believe that Bob can be
  10. classed as a valuable employee, the type which cannot be
  11. dispensed with. Consequently, I duly recommend that Bob be
  12. promoted to executive management, and a proposal will be
  13. executed as soon as possible."

Later that day, addendum:
"Bob was standing over my shoulder while I wrote the report sent to you earlier today. Kindly re-read ONLY the odd numbered lines."

This is an example of steganography - hiding a message within another message. Reading only lines 1, 3, 5, 7, 9, 11, 13 reveals the true message!


Example 2: Hidden Message Letter

Hidden message in highlighted text:
"your package ready Friday 21st room three destroy this immediately"


Steganography

Definition: Method to conceal a file or message within another file, message, image or video

Least Significant Bits (LSB) Method

  • An image file contains a binary representation of the color or light intensity of each pixel.
  • To do steganography, change the least significant bit of the image to be the information we want to hide.

Example:

Original pixel RGB values:
R202 G212 B75  → R203 G113 B75
R198 G99 B59   → R198 G98 B58
R209 G124 B65  → R208 G126 B67
...

Think of LSB steganography like changing a few grains of sand on a beach - the overall appearance stays the same, but the details contain hidden information.

Visual Comparison

  • JPEG file without embedded text vs JPEG file with embedded text
  • The images look identical to the human eye!

Another Steganography Method


Encoding message on an image using position:

Secret Data: H J K L M D A B C P F G E I

Carrier: Grid numbered 1-72

Encoding: Each letter mapped to specific grid positions
Result: Message hidden in carrier image

Cryptographic Algorithms

Key Concepts

  • Mathematical functions that work with a key
  • Security of data relies on:
    • Strength of the algorithm
    • Secrecy of the key

Important Principles

  • Usually, the key is kept secret
  • But, the encryption algorithm is known publicly (Kerckhoffs's principle)
  • The same plaintext data is encrypted into different ciphertext with different keys
Enc(M1,K)=CT1\text{Enc(M1,K)}=\text{CT1} Enc(M1,K2)=CTx\text{Enc(M1,K2)}=\text{CTx}

Like a lock and key system: everyone knows how the lock works, but only the person with the right key can open it.


What is Encryption Used For?

Primary Uses

  1. Prevent eavesdropping
    • Must have a secure channel for key exchange
    • เวลาจะส่งข้อความ แล้วให้อีกฝ่ายอ่านได้ เราก็ต้องส่ง Key ไปให้ถูกมะ เราก็มี techinque ที่จะ encrypt key อีกทีนะ
  2. Secure storage
    • I have to remember my key
  3. Authentication
    • Challenge/Response – verify who sends and who receives
  4. Integrity check
    • Encrypt the checksum of the message

How Cryptography Provides Security

Five Security Services

  1. Confidentiality
    • Allow only authorized users to access information
  2. Authentication
    • Verify who the sender was and trust the sender is who they claim to be
  3. Integrity
    • Trust the information has not been altered
  4. Non-repudiation
    • Ensure that sender or receiver cannot deny that a message was sent or received
  5. Access control
    • Restrict availability to information

Classification of Cryptographic Systems

Classified according to three dimensions:

1. Type of Operations Used

  • Substitution: Replace characters with other characters
  • Transposition (Permutation): Rearrange the order of characters
  • Product system: Combination of both methods

2. Number of Keys Used

  • Symmetric/single-key/secret-key/conventional encryption
    • Symmetric Encryption - we use the same key to both encrypt and decrypt
  • Asymmetric/two-key/public-key encryption
    • Each user we have both public key and private key (key-pair)

3. Way Plaintext is Processed


Symmetric vs. Asymmetric Encryption

(a) Symmetric Cryptosystem

Plaintext → [Encryption] → Ciphertext → [Decryption] → Original Plaintext
                ↑                           ↑
               Key ←────────────────────────┘
           (Same key for both)

  • Easy to use
  • Faster
  • Example: AES

(b) Asymmetric Cryptosystem

Plaintext → [Encryption] → Ciphertext → [Decryption] → Original Plaintext
              ↑                             ↑
        Encryption Key              Decryption Key
        (Different keys)

  • Example: RSA, Electric curve

เราจะไม่พูดว่าอันไหนปลอดภัยกว่า แต่จริง ๆ แล้ว AES ยังไม่สามารถ Attack ได้นะ แต่ RSA 5-6 ปีก็ crack ได้ละ


Symmetric Encryption

Goal: Confidentiality

Process Flow

Sender                                              Recipient
  │                                                     │
  ├─ Plaintext                                         │
  │      ↓                                             │
  ├─ [Encrypt] ←── Shared secret key ───→ [Decrypt]   │
  │      ↓                                      ↓      │
  └─ Ciphertext ──────────────────────→   Plaintext ──┘

Detailed Components

Sender Side:

  • Plaintext input (X)
  • Encryption algorithm (e.g., AES)
  • Secret key shared by sender and recipient (K)
  • Output: Y = E[K,X] (Transmitted ciphertext)

Recipient Side:

  • Transmitted ciphertext (Y)
  • Decryption algorithm (reverse of encryption)
  • Same secret key (K)
  • Output: X = D[K,Y] (Plaintext output)


Symmetric Encryption Methods

Classical Methods

Focus on confidentiality of sending messages

  • Substitution: One letter is exchanged for another
  • Transposition: The order of letters is rearranged
  • Product system: Combination of both methods

Modern Methods

Provide more features than classical methods:

  • Authenticity
  • Anonymity
  • Integrity

Examples:

  • Data Encryption Standard (DES) – Broken
  • Advanced Encryption Standard (AES) – Current standard

Symmetric Encryption: Substitution vs. Transposition

Substitution Example

Mapping table:
a b c d e f g
g b c d 6 @ a

message → w688ga6

Transposition Example

  • หรือจะเรียก Transposition ว่า Permutation
Mapping table:
0 1 2 3 4 5 6
3 0 2 1 5 4 6

message → essmgae

Substitution changes what the letters are (like replacing A with Z), while transposition changes where the letters are (like rearranging "cat" to "act").


Symmetric Encryption: Substitution - Caesar Cipher

How It Works

  1. Replace each character with a number:
    • A=0, B=1, C=2, ..., X=23, Y=24, Z=25
  2. Add the key value to each number (e.g., key=3)
  3. Convert back to a character corresponding to that number
  4. Note: No transformation for characters not in the mapping list

Mathematical Formula

Encryption: Ci=(Pi+3) mod 26\boxed{C_i = (P_i + 3) \bmod 26}
Decryption: Pi=(Ci−3) mod 26\boxed{P_i = (C_i - 3) \bmod 26}

Where:

  • CiC_i = ciphertext character
  • PiP_i = plaintext character

Caesar Cipher with Key = 13 (ROT13)

Shift of 13 positions:

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

Example:
HELLO → URYYB

Caesar Cipher Variations

General Caesar Cipher:
Ci=E(Pi,K)=(Pi+K) mod 26\boxed{C_i = E(P_i, K) = (P_i + K) \bmod 26}

Variations:

  1. Multiplicative: Ci=E(Pi,K)=(n⋅Pi+K) mod 26C_i = E(P_i, K) = (n \cdot P_i + K) \bmod 26
  2. Reflective: Ci=E(Pi,K)=(n(26−Pi)+K) mod 26C_i = E(P_i, K) = (n(26 - P_i) + K) \bmod 26
  3. Quadratic: Ci=E(Pi,K)=(a⋅Pi2+b⋅Pi+K) mod 26C_i = E(P_i, K) = (a \cdot P_i^2 + b \cdot P_i + K) \bmod 26

Where:

  • KK = key of encryption
  • All possible transformations = 26!≈4×102626! \approx 4 \times 10^{26}

Exercise 1

Find the ciphertext of "Thammasat" using Caesar Cipher given that:
Ci=(Pi+3) mod 26C_i = (P_i + 3) \bmod 26

Cryptanalysis of Caesar Cipher

Patterns of Frequency Distribution

Weakness: Character frequency patterns remain the same!

  • In English, 'E' is the most common letter
  • After Caesar cipher, the most common letter in ciphertext reveals the shift

Result: Cryptanalyst can use frequency analysis to break encryption without searching 26!26! combinations

If you shift every letter by 3, 'E' becomes 'H'. If 'H' appears most often in your ciphertext, you know the shift is probably 3!

Symmetric Encryption: Polyalphabetic Substitutions

Purpose

To flatten the frequency distribution of alphabets using multiple substitution functions

Vigenère Cipher

  • A collection of 26 permutations
  • Uses a 26 × 26 matrix
  • All letters appear in each row and column

How it works:

  • The key is a sequence of letters
  • A plaintext letter is the index to a row
  • A key letter is the index to a column
  • The intersection gives the ciphertext letter

Example:

  • Plaintext = THAMMASAT
  • Key = SIIT (repeated)

Vigenère Cipher Table

The Modern Vigenère Tableau

    a b c d e f g h i j k l m n o p q r s t u v w x y z
a   A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
b   B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
c   C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
d   D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
e   E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
f   F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
g   G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
h   H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
i   I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
j   J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
k   K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
l   L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
m   M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
n   N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
o   O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
p   P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
q   Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
r   R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
s   S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
t   T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
u   U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
v   V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
w   W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
x   X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
y   Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
z   Z A B C D E F G H I J K L M N O P Q R S T U V W X Y

"Perfect" Substitutions

Characteristics

  • Use random distribution for many alphabets
  • No predictable pattern for the choice of an alphabet
  • A perfect key: an unlimited, non-repeating series of numbers

Result

  • The repeated plaintext would not be encrypted the same way twice
  • The duplication of two ciphertext letters is almost accidental

Some Efforts

  • One-time pad
  • Vernam Cipher

One-Time Pad

Concept

  • Using a large non-repeating set of keys having the same length as the message
  • The key is used only once

Three Problems

  1. How to generate the key & have safe distribution of keys
  2. Need absolute synchronization between sender and receiver
  3. Need unlimited number of keys

Solution Approach

  • Using time synchronization
  • Key is changing every minute

One-Time Pad (Formal)

Let Zm={0,1,…,m−1}Z_m = \{0, 1, \ldots, m-1\} be the alphabet.

Components:

  • Plaintext space = Ciphertext space = Key space = (Zm)n(Z_m)^n
  • The key is chosen uniformly randomly

Given:

  • Plaintext: X=(x1,x2,…,xn)X = (x_1, x_2, \ldots, x_n)
  • Key: K=(k1,k2,…,kn)K = (k_1, k_2, \ldots, k_n)
  • Ciphertext: Y=(y1,y2,…,yn)Y = (y_1, y_2, \ldots, y_n)

Operations:

Encryption: eK(X)=(x1+k1,x2+k2,…,xn+kn) mod m\boxed{e_K(X) = (x_1+k_1, x_2+k_2, \ldots, x_n+k_n) \bmod m}
Decryption: dK(Y)=(y1−k1,y2−k2,…,yn−kn) mod m\boxed{d_K(Y) = (y_1-k_1, y_2-k_2, \ldots, y_n-k_n) \bmod m}

The Binary Version of One-Time Pad

Simplified for binary:

  • Plaintext space = Ciphertext space = Keyspace = {0,1}n\{0,1\}^n
  • Key is chosen randomly

Example:

Plaintext:    11011011
Key:          01101001
            ⊕ (XOR)
Ciphertext:   10110010

XOR Truth Table:

ABA ⊕ B
000
011
101
110

Vernam Cipher

Use a long non-repeating sequence of numbers to be combined with the plaintext

Example

PlaintextVERNAM
Numeric Equivalent21041713012
+ Random number764816824403
= Sum975233954415
= mod 261907171815
CiphertextTAHRSP

Why Vernam Cipher is Called "One-Time Pad"

It is an unbreakable cipher when:

  • The key is exactly the same length as the message
  • The key is used one time only
  • The key is never used again for any other message

Think of it like a scratch-off lottery ticket - once you've used it, you throw it away and never use it again.

Key Randomness in One-Time Pad

Question: What if the key is not chosen randomly?

For example, if texts from a book/dictionary are used as keys:

  • This is NOT One-Time Pad anymore
  • This does NOT have perfect secrecy
  • This CAN be broken

Why?

  • Natural language has patterns and redundancies
  • These patterns can be exploited by cryptanalysts

Key Reuse Problem

The key in One-Time Pad should NEVER be reused.

If it is reused:

  • It becomes "Two-Time Pad"
  • It is insecure!

Why? The attacker can learn and study the relationship between ciphertexts

If two messages M1M_1 and M2M_2 are encrypted with the same key KK:
C1=M1⊕KC_1 = M_1 \oplus K
C2=M2⊕KC_2 = M_2 \oplus K
Then:
C1⊕C2=(M1⊕K)⊕(M2⊕K)=M1⊕M2C_1 \oplus C_2 = (M_1 \oplus K) \oplus (M_2 \oplus K) = M_1 \oplus M_2

The key cancels out, exposing patterns between the two messages!


Usage of One-Time Pad

The Challenge

To use one-time pad, one must have keys as long as the messages.

To send messages totaling certain size, sender and receiver must agree on a shared secret key of that size.

  • Typically by sending the key over a secure channel

The Paradox

Question: Can't one use the channel for sending the key to send the messages instead?

Answer: Not necessarily! The secure channel may have different properties.

Why is OTP Still Useful?

The secure channel for distributing keys may have the property that:

  • Keys can be leaked
  • BUT such leakage will be detected

Example:

  • Quantum cryptography allows key distribution where any eavesdropping can be detected

Like a tamper-evident envelope - if someone tries to peek at the key, you'll know about it!


Symmetric Encryption: Transposition (Permutation)

Goal: Rearrange letters in a message to break established patterns

Columnar Transpositions

  • Rearrangement of plaintext characters into columns
  • May use 'x' to fill in any short column

Example:

  • Message: "this is a message to show"
T H I S I
S A M E S
S A G E T
O S H O W

Reading column by column:

TSSO HAAS IMGH SEEO ISTW

Disadvantages

  • Delay since all characters must be received before decoding
    • Needs to get complete ciphertext, before decrypting it (not on the fly)

Columnar Transposition Examples

Example 1: Simple Column Rearrangement

Original:    d b a c
Key order:   2 3 4 1

Result:      Rearrange columns according to key

Example 2: With Message

Message: JAMESBONDNEEDSBACKUP
Code: JEONDAUASNESCPMBDEBK

Grid arrangement (key order determines column reading):
J  E  O  N  D  A  U
A  S  N  E  S  C  P
M  B  D  E  B  K

Reading in key order gives the ciphertext.


Symmetric Encryption: Product Cipher

Concept

  • Objective: Increase cipher strength
  • Method: Combine two techniques of basic ciphers
  • Have many steps and perform one after another

Important Note

However, two ciphers in combination are not always stronger than individual cipher!

Like mixing two locks - sometimes it's more secure, but if one lock is weak, the whole thing might still be vulnerable.


Shannon's Characteristics of Good Ciphers

Claude Shannon (Father of Information Theory)

Six Characteristics

  1. The amount of secrecy needed should determine the amount of labor appropriate for encryption/decryption
    • The degree of secrecy ก็ขึ้นอยู่กับว่าเราต้องใช้คน/resource มากแค่ไหนในการ encrypt/decrypt
    • ใช้ทั้งหมดที่มีในชีวิตในการ decrypt/encrypt - Aj. Somchart (Ohm)
  2. Set of keys and algorithm should be free from complexity
  3. Implementation should be simple
  4. Should have no error propagation that causes the corruption of further message
    • Error Propagation
    • M1, M2, …, Mn → CT1, CT2, …, CTn
    • Problem with M1 or CT1, it should not be propagated with M2, and so on.
  5. Size of ciphertext should be no longer than that of plaintext
    • Why? Longer ciphertext means more data to transmit and store (You give more information to the attacker!)
  6. The algorithm should be mathematically sound and provably secure

Security of Encryption

1. Unconditionally Secure Algorithm

  • No matter how much computer power or time is available, the cipher cannot be broken
  • The ciphertext provides insufficient information to uniquely determine the corresponding plaintext
  • Only one method is unconditionally secure: One-Time Pad

ไม่ว่าจะใช้ supercomputer เริ่ดแค่ไหน ก็ไม่สามารถแก้ ciphertext นี้ได้ ถ้าใช้ one-time pad

2. Computationally Secure Algorithm

  • Given limited computing resources, the cipher cannot be broken
  • Encryption is computationally secure if:
    • Cost of breaking cipher exceeds information value, OR
    • Time required to break cipher exceeds the useful lifetime of the information

Reality:

  • Usually very difficult to estimate the amount of effort required to break
  • Can estimate time/cost of a brute-force attack

แตกได้ในทางทฤษฎี (crack ได้)
แต่ ในทางปฏิบัติ = ไม่คุ้ม / ทำไม่ได้จริง


Cryptanalysis: Breaking the Key

Attack Types

Brute-Force Attack

  • Try all possible keys
  • Guaranteed to work eventually, but may be infeasible

Cryptanalysis Attacks

Know something about the system:

  1. Ciphertext only – The hardest one
  2. Known plaintext – Know some plaintext-cipher pairs
  3. Chosen plaintext – Get own plaintext-cipher pairs
  4. Chosen ciphertext – Not easy to find

Types of Cryptanalytic Attacks

Type of AttackInformation Known to Cryptanalyst
Ciphertext only• Encryption algorithm
• Ciphertext to be decoded
Known plaintext• Encryption algorithm
• Ciphertext to be decoded
• Plaintext-ciphertext pairs generated by the secret key
Chosen plaintext• Encryption algorithm
• Ciphertext to be decoded
• Plaintext chosen by cryptanalyst and corresponding ciphertext generated by the secret key
Chosen ciphertext• Encryption algorithm
• Ciphertext to be decoded
• Ciphertext chosen by cryptanalyst, corresponding plaintext generated by the secret key

Ciphertext-Only Attack


Scenario:

  • Eve (attacker) can only observe the ciphertext
  • Must deduce plaintext or key from ciphertext alone
Alice                   Eve                     Bob
  │                      │                       │
  ├─ Plaintext          │                       │
  │      ↓              │                       │
  ├─ [Encrypt]          │                       │
  │      ↓              │                       │
  └─ Ciphertext ───────►├─ [Analyze] ───────►  │
                         │      ↓               │
                         └── Plaintext          └─ Ciphertext
                             (attempt)              ↓
                                               [Decrypt]
                                                   ↓
                                               Plaintext

This is the weakest attack model from the attacker's perspective - like trying to decode a message with no hints at all.


Known-Plaintext Attack (KPA)

Definition: A cryptanalytic attack model where the attacker knows:

  • One or more plaintext messages, and
  • Their corresponding ciphertexts
  • Both encrypted under the same secret key

Goal: Recover the secret key or decrypt other ciphertexts encrypted with that key

Alice                   Eve                           Bob
  │                      │                             │
  ├─ Plaintext          │   ┌──────────────┐         │
  │      ↓              │   │Previous pair:│         │
  ├─ [Encrypt]          │   │Plaintext ←→ │         │
  │      ↓              │   │ Ciphertext  │         │
  └─ Ciphertext ───────►├───┴──────────────┘         │
                         │      ↓                     │
                         ├─ [Analyze]                 │
                         │      ↓                     │
                         └── Plaintext                └─ Ciphertext
                             (attempt)                    ↓
                                                     [Decrypt]
                                                         ↓
                                                     Plaintext

Chosen-Plaintext Attack (CPA)

Attacker know the source


In this attack:

  • The attacker/cryptanalyst can select or choose the plaintext
  • The plaintext is sent through the encryption algorithm
  • The attacker observes the resulting ciphertext

This is an active model where the attacker actually gets to choose the plaintext and do the encryption.

     ┌──────────────────────┐
     │Pair created from     │
Eve ──┤chosen plaintext      │
     │Plaintext → Ciphertext│
     └──────────────────────┘
             ↓
Alice                   Eve                           Bob
  │                      │                             │
  ├─ Ciphertext         │                             │
  │      ↓              │                             │
  │                     ├─ [Analyze]                  │
  │                     │      ↓                      │
  │                     └── Plaintext                 └─ Ciphertext
  │                         (attempt)                     ↓
  │                                                   [Decrypt]
  │                                                       ↓
  └────────────────────────────────────────────────► Plaintext

Formal Definition - CPA

Let:

  • EK(⋅)E_K(\cdot) be an encryption algorithm with secret key KK

In a chosen-plaintext attack, the adversary is allowed to:

Query EK(P)E_K(P) for any plaintext PP of their choice

The attacker's goal is to:

  • recover KK, or
  • distinguish encryptions of chosen messages, or
  • break semantic security

Simple Example: Caesar Cipher (Broken under CPA)

Encryption:
Ci=(Pi+k) mod 26C_i = (P_i + k) \bmod 26
Attacker chooses:
P=AP = A
Receives:
C=DC = D
Conclusion:
Since A=0A = 0 and D=3D = 3:
k=3k = 3
The key is recovered in one query!


Chosen-Ciphertext Attack (CCA)


In this attack:

  • The attacker can both encrypt and decrypt
  • They can select plaintext, encrypt it, observe the ciphertext
  • Then reverse the entire process

Note: The cryptanalyst is trying to decipher the algorithm and secret key, not necessarily just find the plaintext.

Alice                   Eve                           Bob
  │                      │   ┌──────────────────┐    │
  ├─ Ciphertext         │   │Pair created from:│    │
  │      ↓              │   │Chosen ciphertext │    │
  │                     ├───┤Ciphertext        │    │
  │                     │   │     ↓            │    │
  └─────────────────────┼───┤[Decrypt]         │    │
                        │   │     ↓            │    │
                        │   │Plaintext         │    │
                        │   └──────────────────┘    │
                        │      ↓                     └─ Ciphertext
                        ├─ [Analyze]                     ↓
                        │      ↓                     [Decrypt]
                        └── Plaintext                    ↓
                                                     Plaintext

CCA - Chosen-Ciphertext Attack

Overview

A Chosen-Ciphertext Attack (CCA) is the strongest and most realistic attack model in symmetric and public-key cryptography.

In a CCA, the attacker can actively submit ciphertexts of their choice to a decryption oracle and observe the corresponding plaintexts—with one critical restriction in the formal game.

Attacker Capabilities

In a CCA, the attacker can:

  • Choose plaintexts and see their encryptions (CPA power), and
  • Choose ciphertexts and see their decryptions

Goals

  • Recover the secret key, or
  • Distinguish which plaintext was encrypted

What Is an Oracle?

In cryptography, an oracle is an abstract, black-box interface that answers specific queries for an attacker or algorithm, as if a perfect service were available.

Think of an oracle like a magic box: you can ask it questions (like "decrypt this"), and it gives you answers, but you can't see how it works inside.


Formal Security Notions - CCA

IND-CCA (Indistinguishability under CCA)

Game outline:

  1. Attacker can query:

    • Encryption oracle EK(⋅)E_K(\cdot)
    • Decryption oracle DK(⋅)D_K(\cdot)
  2. Attacker submits two messages m0,m1m_0, m_1

  3. Challenger returns:
    c∗=EK(mb),b∈{0,1}c^{*} = E_K(m_b), \quad b \in \{0, 1\}

  4. Attacker may continue decryption queries except on c∗c^{*}

  5. Attacker guesses bb

A scheme is IND-CCA secure if the attacker's advantage is negligible.

Idea: ถ้าเราเอาไปผ่านหลาย ๆ algorithm ในการ encrypt มันมีผลยังไงใน math ของเวลาในการ crack


Step 3 — Challenge Ciphertext Generation

What happens:

The attacker submits two plaintexts of equal length:
m0,m1m_0, m_1
The challenger:

  1. Picks a random bit:
    b←{0,1}b \leftarrow \{0, 1\}

  2. Encrypts only one of them:
    c∗=EK(mb)c^{*} = E_K(m_b)

  3. Sends c∗c^{*} to the attacker

What this step means

This is the core challenge:

"Can you tell which plaintext was encrypted?"

The attacker knows:

  • Both m0m_0 and m1m_1
  • The encryption algorithm

But does not know:

  • The key KK
  • The random bit bb

If the attacker can guess bb with probability significantly greater than 1/21/2, the scheme is not secure.

Step 4 — Restricted Decryption Queries

What happens:

After receiving c∗c^{*}, the attacker may:

  • Continue querying the decryption oracle:
    DK(C)D_K(C)
    ⚠️ With one strict restriction:
    C≠c∗C \neq c^{*}
    The attacker is not allowed to decrypt the challenge ciphertext itself.

Why this restriction is necessary

If the attacker could query:
DK(c∗)D_K(c^{*})
Then:
DK(c∗)=mbD_K(c^{*}) = m_b
This would trivially reveal which message was encrypted!

The restriction prevents the attacker from simply asking for the answer directly.

Remark on Steps 3 and 4

Step 3 creates a challenge ciphertext encrypting one of two chosen messages.

Step 4 allows the attacker to decrypt any ciphertext except the challenge itself.

This models realistic adaptive attacks while preventing trivial key recovery.

Think of it like a test: you can practice with similar problems (Step 4), but you can't look up the answer to the actual test question (Step 3).

Why Step 4 is the Core of CCA Strength

This step allows attacks like:

  • Modifying bits of c∗c^{*}
  • Observing accept/reject behavior
  • Exploiting error messages, padding checks, MAC failures

If any information leaks, the attacker may still infer mbm_b.

A scheme that survives this is truly robust.

Step 4 Is Where CCA Attacks Happen

Recall Step 4 in IND-CCA:

The adversary may query a decryption oracle on any ciphertext except the challenge ciphertext.

If the decryption algorithm:

  • Outputs plaintext, or
  • Leaks any distinguishable information (errors, timing, padding validity)

Then the attacker can adaptively modify ciphertexts and learn information about the challenge.

⚠️ This is exactly how CCA attacks work.

How to Enable Step 4 to be CCA-Resistant?

When authentication is added (e.g., AEAD):

\text{Reject} & \text{if MAC/tag invalid} \\ P & \text{otherwise} \end{cases}$$ **Key property:** > **Modified ciphertexts are rejected without revealing anything.** **This means in Step 4:** - The decryption oracle becomes **non-informative** for forged ciphertexts - No exploitable feedback exists > It's like a sealed envelope with a tamper-evident seal - if someone modifies it, you know immediately and don't open it. --- ## AEAD - Authenticated Encryption with Associated Data ### Definition **AEAD** stands for **Authenticated Encryption with Associated Data**. It is a cryptographic paradigm that simultaneously provides: - **Confidentiality** - **Integrity** - **Authenticity** It is the **standard way to achieve IND-CCA security** in practice. ### Two Inseparable Security Properties 1. **Confidentiality** - The plaintext cannot be learned from the ciphertext 2. **Integrity & Authenticity** - Any modified or forged ciphertext is **detected and rejected** **Together, these imply IND-CCA security.** ___ ## What Is "Associated Data"? **Associated Data (AD)** is data that: - Must be **authenticated** - But does **not need confidentiality** ### Examples - Protocol headers - IP addresses - Sequence numbers - Device IDs - Access-control metadata **If AD is modified → decryption fails.** > Think of AD like the "To:" address on an envelope - it doesn't need to be secret, but it must be authentic so the letter isn't tampered with. --- ## AEAD Syntax (Formal) An AEAD scheme consists of two algorithms: ### Encryption $$(C, T) = \text{Enc}_K(N, P, A)$$ ### Decryption $$P \text{ or } \bot = \text{Dec}_K(N, C, T, A)$$ Where: - $K$ = secret key - $N$ = nonce (unique per key - random number) - $P$ = plaintext - $A$ = **associated data** (authenticated but not encrypted) - $C$ = ciphertext - $T$ = authentication tag - $\bot$ = reject ### The Authentication Tag **The authentication tag is like a tamper-evident seal.** - If the message is altered → the seal breaks - If the seal is intact → the message is authentic > Like a wax seal on a letter - if the seal is broken, you know someone opened it. > ทั้งหมดนี้เป็นเหมือน Integrity check??!!!! --- ## AES-GCM (Galois/Counter Mode) ### Overview - **AEAD scheme:** provides confidentiality + integrity - **Combines:** - **AES** (block cipher) for encryption - **GHASH** (Galois-field MAC) for authentication ### Widely deployed - TLS 1.3, HTTPS - Cloud storage & APIs - VPNs, IoT systems **⚠️ IND-CCA secure when used correctly** ### AES-GCM Inputs and Outputs #### Encryption Input - Secret key $K$ (128 / 192 / 256 bits) - Nonce $N$ (96-bit, **must be unique**) - Plaintext $P$ - Associated Data $AD$ (authenticated, not encrypted) #### Encryption Output $$(C, T) = \text{Enc}_K(N, P, AD)$$ Where: - $C$: ciphertext - $T$: authentication tag (usually 128 bits) ### Encryption Process (High Level) #### Step 1: AES in Counter Mode (CTR) AES in counter mode encrypts plaintext #### Step 2: GHASH Computation GHASH computes authentication over: - Ciphertext - Associated Data - Nonce #### Step 3: Tag Generation Authentication tag $T$ is generated #### Summary ``` Plaintext ──> AES-CTR ──> Ciphertext Ciphertext, AD, lengths ──> GHASH ──> Authentication Tag ``` ### GHASH Process GHASH works over the finite field: $$\text{GF}(2^{128})$$ #### Let: - $H = \text{AES}_K(0^{128})$ ← hash subkey - $X_1, X_2, \ldots, X_n$ = 128-bit blocks of AD and ciphertext #### GHASH is defined as: $$\text{GHASH}_H(X_1, \ldots, X_n) = (((X_1 \cdot H \oplus X_2) \cdot H \oplus \ldots) \cdot H)$$ **All operations are in GF($2^{128}$)** Multiplication is polynomial multiplication modulo a fixed irreducible polynomial. #### Why GHASH Is Secure - Without knowing key $K$, attacker cannot compute valid GHASH - Forging a valid tag has probability: $$\leq 2^{-128}$$ (for a 128-bit tag) > Like trying to guess a 128-bit password - virtually impossible ### How the Authentication Tag Is Formed **Final AES-GCM tag:** $$T = \text{AES}_K(J_0) \oplus \text{GHASH}_H(\text{AD}, C, \text{len})$$ #### Where: - $J_0$ is derived from the nonce - GHASH ensures integrity - AES ensures secrecy of the tag ### Decryption Rule (Critical) $$P \text{ or } \bot = \text{Dec}_K(N, C, T, AD)$$ **Steps:** 1. **Verify authentication tag first** 2. If tag invalid → **reject** ($\bot$) 3. If tag valid → decrypt and return plaintext **⚠️ Never decrypt before tag verification** > This is crucial for CCA security - always check the seal before opening the envelope! ### Security Comparison | Aspect | AES (alone) | AES-GCM | | ----------------- | ----------- | -------------------------- | | Encryption | ✓ Yes | ✓ Yes | | Integrity | ✗ No | ✓ Yes | | Authentication | ✗ No | ✓ Yes | | Misuse resistance | ✗ Low | ⚠️ Medium | | IND-CPA secure | ✓ Yes | ✓ Yes | | IND-CCA secure | ✗ No | ✓ Yes (if nonce is unique) | | | | | ___ ## Data Security: Best Practices ### Three-Step Approach 1. **Protect Data** - Encrypt or Tokenize - Apply Access Controls 2. **Protect Keys** - Separate key management from data security - Manage Key Lifecycle - Apply Access Controls > The chain of security: protect your data with keys, then protect those keys with careful management. --- ## Data Protection: A Three Step Approach ### Step 1: Locate Sensitive Data **Where data lives:** - File Servers (DAS, SAN, NAS, HDFS) - Databases (SQL & NoSQL) - Applications (Application servers) - Public Cloud (Cloud Servers and Virtual Machines) --- ### Step 2: Encrypt Sensitive Data + Access Control **Protection methods:** - File Level Encryption - Database Level Encryption - Application Level Encryption - Tokenization **+ Access Control** at each level --- ### Step 3: Manage Encryption Keys **Key Management includes:** - Centralized Key Management (Generation, Rotation, Expiration, etc.) - Audit Reporting and Compliance Management - **Separation of duties** – Encryption Keys decoupled from data --- ## Historical Context: Rotor Machines **A rotor machine is an electro-mechanical stream cipher device used for encrypting and decrypting secret messages during WWII** ### Famous Rotor Machines - **Enigma** - German - **Purple** - Japan - **TypeX** - England - **SIGABA** - US [Images of Enigma, TypeX, SIGABA, and Purple machines] --- ## Common Symmetric Cryptography Algorithms ### Historical Timeline - **Lucifer** (1975) from IBM - **DES** (1977) - **IDEA** (1992) - **Blowfish** (1993) - **RC5** (1995) - **Triple DES** (1998) - **AES** (2001) ← **Current Standard** --- ## Symmetric Encryption ### Symmetric Encryption: Design Principles #### 1. General Structure Have a general **iterative block cipher structure** - With **number of rounds** - With **substitutions/permutations** controlled by key #### 2. Parameters - **Block size** and **key size** - **Algorithm to generate subkey** (used for each round) - **Different round function** for each round #### 3. Implementation - Fast software implementation and execution - Key size VS Security - Longer is better than shorter, but slower --- ### Symmetric Encryption: DES #### History - IBM developed DES (modification of **Lucifer**, a previous cipher) and published in **1975** - DES was adopted as the encryption standard in **1977** by NIST called **Data Encryption Standard** - DES was used till **2001** as replaced by **AES** #### Parameters - **Block size:** 64 bits - **Key size:** 56 bits (too short มะะ) - **Subkey:** 48 bits - **Rounds:** 16 --- ## DES Overview ### Structure ``` 64-bit plaintext 56-bit key ↓ ↓ [Initial permutation] [Permuted choice 1] ↓ ↓ Round 1 ←─── K₁ ←───[Permuted choice 2]←─[Left circular shift] ↓ ↓ Round 2 ←─── K₂ ←───[Permuted choice 2]←─[Left circular shift] ↓ ... ↓ Round 16 ←─── K₁₆ ←──[Permuted choice 2]←─[Left circular shift] ↓ [Inverse initial permutation] ↓ 64-bit ciphertext ``` ![[Screenshot 2026-01-24 at 7.01.54 PM.png|center|400]] --- ## Security of DES ### Known Weaknesses - A **56-bit key is too short** (Diffie-Hellman, 1977) ### Breaking Timeline - **1997:** 3500 machines in parallel can solve a DES key in **4 months** - **1998:** A special "DES cracker" was built for about **$100,000** to find a DES key in **4 days** ### Weak Keys DES has **4 weak keys** since they generate the same subkeys for every round: 1. `00000000 00000000` 2. `00000000 FFFFFFFF` 3. `FFFFFFFF 00000000` 4. `FFFFFFFF FFFFFFFF` --- ## DES with Multiple Keys ### The Problem - DES: vulnerable to brute-force attack - Need a replacement ### Two Approaches **(1) Completely new design → AES** **(2) Use multiple encryption with DES** – to preserve existing investment **Options:** - Double DES - Triple DES with two keys (effective 112-bit key length) - Triple DES with three keys (effective 168-bit key length) --- ## Triple DES (3DES) ### Usage - Adopted for use in email applications: **PGP** and **S/MIME** - Combine 3 DES using 3 keys ### Formula $$\boxed{C = E(K_3, D(K_2, E(K_1, P)))}$$ Where: - $E$ = Encrypt - $D$ = Decrypt - $P$ = Plaintext - $C$ = Ciphertext ### Properties - **Decryption is the same with keys reversed** - **Slow but secure** ### Triple DES with Two Keys - Use $K_1 = K_3$ - Effective key length: 112 bits ### E-D-E Sequence **E-D-E (Encrypt-Decrypt-Encrypt) sequence helps support backward compatibility:** - Single DES user can encrypt - 3DES user can decrypt data from DES user - If $K_1 = K_2 = K_3$, it behaves like single DES ### Triple DES (3DES) Diagram ![[Pasted image 20260113153117.png|center|500]] ![[Screenshot 2026-01-24 at 7.16.17 PM.png|center|500]] ``` Key K1 Key K2 Key K3 ↓ ↓ ↓ $1000 → [Encrypt] → $!@# → [Decrypt] → df5&4r → [Encrypt] → fie9r3 ``` ### EDE (Encrypt-Decrypt-Encrypt) Method – 3DES-EDE Method: - Data is encrypted using K1 - Data is decrypted using K2 - Data is encrypted using K3 **Key Lengths:** - If $K_1 = K_3$: Key Yields **112-Bit Key Length** - If $K_1 \neq K_3$: Key Yields **168-Bit Key Length** --- ## Advanced Encryption Standard (AES) ### History - In **1997**, NIST made a formal call for a new encryption standard ### AES Specifications - ✓ Unclassified and publicly disclosed - ✓ Available royalty-free for use worldwide - ✓ Symmetric block cipher of **128 bits** - ✓ Key size: **128, 192, 256 (Default), 512 bits** ### Selection Process - **1998:** NIST announced a group of **15 candidates** - **1999:** Selection narrowed to **5 finalists:** - MARS - RC6 - **Rijndael** ← Winner - Serpent - Twofish ### The Winner - **Rijndael** from Rijmen-Daemen (Belgium mathematicians) - Rijndael was selected as the AES in **2000** - *Rijndael is pronounced "Rine-dahl" in Dutch* --- ## Overview of AES (Rijndael) ### Design Philosophy - A **fast algorithm** to be implemented easily on simple processors - Has a **strong mathematical foundation** - Uses polynomial representation in **GF ($2^8$)** (Galois Field) ### Structure - **Symmetrical parallel structure** - **Byte-oriented operations** - Use **repeating rounds** ### Four Main Operations 1. **Byte Substitution** (SubBytes) 2. **Shift Rows** 3. **Mix Columns** 4. **Add Round Key** >จำให้ได้เด้อ ๆ ๆ ๆ ๆ ๆ ๆ ๆ >Four main operations >Size per data block = 128 bits block size --- ## General Design of AES ![[Pasted image 20260113153349.png|center|500]] ``` 128-bit plaintext Cipher key ↓ (128, 192, or 256 bits) [Pre-round transformation] ←─ K₀ ↓ ↓ │ Round 1 ←────────── K₁ ←──────────── │ ↓ Key expansion Round 2 ←────────── K₂ ←──────────── │ ↓ │ ... │ ↓ │ Round Nᵣ ←────────── K_Nᵣ ←────────────┘ (slightly different) ↓ 128-bit ciphertext ``` ### Relationship Between Number of Rounds and Cipher Key Size | Nᵣ | Key size | |----|----------| | 10 | 128 | | 12 | 192 | | 14 | 256 | --- ## Process of AES ### Steps 1. **Input block**, cipher key of 128 bits (16 bytes) arranged in 2-D matrix 2. **Initial Add Round Key** 3. **Perform 9 rounds** of: - SubBytes (Byte Substitution) - Shift Rows - Mix Columns - Add Round Key 4. **Perform final round:** - SubBytes (Byte Substitution) - Shift Rows - Add Round Key (no Mix Columns) **Demo:** https://www.youtube.com/watch?v=mlzxpkdXP58 ### Process of AES (Flowchart) ![[Pasted image 20260113153918.png|center|500]] --- ## Strength of the AES ### Security Status - Up to now, **no significant problems have been found** - **No restriction on key selection** (no weak keys) ### Designed to have: - Resistance against known attacks - Speed and code compactness on many CPUs - Design simplicity ### AES Parameters | Key size (words/bytes/bits) | 4/16/128 | 6/24/192 | 8/32/256 | |-----------------------------|----------|----------|----------| | Plaintext block size (words/bytes/bits) | 4/16/128 | 4/16/128 | 4/16/128 | | Number of rounds | 10 | 12 | 14 | | Round key size (words/bytes/bits) | 4/16/128 | 4/16/128 | 4/16/128 | | Expanded key size (words/bytes) | 44/176 | 52/208 | 60/240 | --- ## AES vs. Others ### Comparison of DES, Triple DES, AES and Blowfish algorithm | | **DES** | **TDES** | **AES** | **BLOWFISH** | | ----------------------- | ------------------ | ---------------------- | -------------------------------- | ---------------------- | | **Block Size** | 64 bit | 64 bit | 128 bit | 64 bit | | **Key size** | 56 bit | 168 bit | 128,192, 256 bit | 32-448 bit | | **Created By** | IBM in 1975 | IBM in 1978 | Joan Daeman in 1998 | Bruce Schmeier in 1998 | | **Algorithm Structure** | Fiestel Network | Fiestel Network | Substitution Permutation Network | Fiestel Network | | **Rounds** | 16 | 48 | 9,11,13 | 16 | | **Attacks** | Brute Force Attack | Theoretically possible | Side Channel Attacks | Not Yet | --- ## Appendix: Binary and Hexadecimal ### Binary to Hexadecimal Conversion | Binary | Hexadecimal | |--------|-------------| | 0000 | 0 | | 0001 | 1 | | 0010 | 2 | | 0011 | 3 | | 0100 | 4 | | 0101 | 5 | | 0110 | 6 | | 0111 | 7 | | 1000 | 8 | | 1001 | 9 | | 1010 | A | | 1011 | B | | 1100 | C | | 1101 | D | | 1110 | E | | 1111 | F | --- ## XOR Truth Table | A | B | A XOR B | |---|---|---------| | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 0 | **Properties of XOR:** - $A \oplus 0 = A$ - $A \oplus A = 0$ - $A \oplus B = B \oplus A$ (commutative) - $(A \oplus B) \oplus C = A \oplus (B \oplus C)$ (associative) > XOR is used extensively in cryptography because it's reversible: if $C = A \oplus B$, then $A = C \oplus B$