πŸ” AES Encryption & Decryption

Advanced Encryption Standard Implementation in Python

Practical 3

🎯 Objective

To implement AES encryption and decryption in Python using pycryptodome and understand the basics of AES key expansion and structure.

πŸŽ“ Purpose of the Practical

To implement AES (Advanced Encryption Standard) encryption and decryption using ECB mode. This practical also helps learners understand the importance of key expansion and secure block cipher design used in modern cryptography.

πŸ“š Theoretical Background

What is AES?

  • AES (Advanced Encryption Standard) is a symmetric key block cipher
  • It was adopted as the standard by NIST in 2001, replacing the older DES
  • AES operates on 128-bit blocks and supports key sizes of:
    • 128 bits (16 bytes)
    • 192 bits (24 bytes)
    • 256 bits (32 bytes)

πŸ”§ Key AES Features

Feature Value
Block Size 128 bits (16 bytes)
Key Sizes 128, 192, 256 bits
Type Symmetric Cipher
Structure Substitution–Permutation Network
Rounds (128-bit) 10

πŸ’» Implementation Code

Python Implementation
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad

# 16-byte key (128-bit AES)
key = b'ThisIsASecretKey'
plaintext = b'GECBHARUCH2025'

# AES cipher in ECB mode
cipher = AES.new(key, AES.MODE_ECB)

# Encrypt
ciphertext = cipher.encrypt(pad(plaintext, 16))
print("Encrypted (hex):", ciphertext.hex())

# Decrypt
decrypted = unpad(cipher.decrypt(ciphertext), 16)
print("Decrypted text:", decrypted.decode())

πŸ“€ Output

Encrypted (hex): af79118251b6f9dd37268ff7418d7a40
Decrypted text: GECBHARUCH2025

πŸ”‘ AES Key Expansion Overview

AES generates round keys from the initial key using a process called key expansion.

πŸ”„

10 Rounds

For AES-128, performs 10 encryption rounds

πŸ”‘

11 Round Keys

Uses original key + 10 generated keys

βš™οΈ

Key Operations

RotWord, SubWord, Rcon, XOR operations

This process ensures each encryption round uses a unique and secure key, adding complexity and improving resistance to attacks.

⚠️ Note on ECB Mode

Security Warning

ECB is not secure for sensitive data, because identical plaintext blocks yield identical ciphertext blocks.

More secure modes: CBC, CFB, CTR (recommended for real use cases).

πŸ“Š Comparison with DES (Practical 2)

Feature Practical 2: DES Practical 3: AES
Standard Outdated Current global standard
Key Size 56 bits (effective) 128 bits (can be 192/256)
Block Size 64 bits 128 bits
Rounds 16 fixed 10 for 128-bit key
Security Weak (brute-forceable) Strong (not practically breakable)
Speed Slower, older hardware Faster and more efficient on modern CPUs
Applications Legacy systems Web, banking, cloud, mobile, government

🌍 Real-Life Applications

AES is the current global standard for symmetric-key encryption, and is widely used in:

🏦

Banking

Financial systems and secure PIN encryption

🌐

Web Security

SSL/TLS encryption for websites

πŸ“Ά

WiFi Security

WPA2/WPA3 uses AES encryption

☁️

Cloud Storage

Data protection in cloud, USB drives, smartphones

πŸ›οΈ

Government

Military communications (approved by NIST and NSA)

🎯 Learning Outcomes

After completing this practical, students will:

  • Understand the AES algorithm and its structure
  • Learn to perform encryption and decryption using AES
  • Understand how to pad and unpad data for block cipher use
  • Get an overview of AES key expansion and round keys
  • Realize the limitations of ECB mode and the need for secure modes
  • Be introduced to modern cryptographic security standards

πŸ’‘ Key Observations

AES supports multiple key sizes, improving flexibility and security.

Block size is fixed at 128 bits, ensuring consistency.

AES performs a series of substitutions, permutations, and key additions β€” not just simple shifting or bit-flipping.

Use of Crypto.Cipher.AES abstracts away complex operations, but understanding the internals (e.g., S-boxes, rounds, key schedule) is vital for deeper knowledge.

πŸ“ Summary

This demonstrates AES, the most widely used and trusted symmetric encryption algorithm in the world. Students learn to implement AES in ECB mode, use padding, and handle key management. Compared to DES, AES provides greater security, efficiency, and adaptability, making it essential for modern secure systems. While ECB mode is used here for simplicity, students should be made aware of more secure modes (like CBC, CTR) for production use.