Skip to content

A Python implementation of the AES encryption algorithm in CBC mode, built entirely from scratch.

License

Notifications You must be signed in to change notification settings

mstradaa/AES-CBC-Encryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

AES Encryption - Python Implementation from Scratch

A complete implementation of the Advanced Encryption Standard (AES) algorithm built entirely from scratch in Python, without relying on external cryptographic libraries.

Features

  • Complete AES Implementation: full implementation of AES-128, AES-192, and AES-256.
  • AES S-box and inverse S-box generation.
  • No external cryptographic libraries used.
  • Secure CBC Mode: Cipher Block Chaining with proper IV handling.
  • PKCS7 Padding: standard padding scheme with validation.
  • Cryptographically Secure: uses secure random number generation.

Implementation Details

The implementation consists of two main Python files:

S_BoxGenerator.py

  • Implements the AES S-box and inverse S-box generation
  • Contains Galois Field (GF(2^8)) operations
  • Provides affine transformation for S-box generation
  • Includes utility functions for printing S-boxes

main.py

  • Core AES implementation with support for all key sizes
  • Implements all AES operations:
    • SubBytes/InvSubBytes
    • ShiftRows/InvShiftRows
    • MixColumns/InvMixColumns
    • AddRoundKey
    • Key Expansion
  • CBC mode implementation with PKCS7 padding
  • Interactive demo mode for testing

Usage

Demo

Run the program to test the implementation:

python main.py

The program will:

  1. Let you choose AES version (128/192/256-bit)
  2. Accept input text for encryption
  3. Show detailed security information
  4. Perform encryption and decryption
  5. Verify the results

Specifications

Feature Details
Block Size 128 bits (16 bytes)
Key Sizes 128, 192, 256 bits
Rounds 10 (AES-128), 12 (AES-192), 14 (AES-256)
Mode CBC (Cipher Block Chaining)
Padding PKCS7
IV Size 128 bits (16 bytes)

Additional Notes

  • Uses Python's secrets module for cryptographically secure random number generation
  • Implements proper IV handling in CBC mode
  • Includes padding validation to prevent padding oracle attacks
  • All cryptographic operations are implemented from scratch without external dependencies

This project was developed as part of the coursework for a MSc in Cryptography program.

About

A Python implementation of the AES encryption algorithm in CBC mode, built entirely from scratch.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages