A complete implementation of the Advanced Encryption Standard (AES) algorithm built entirely from scratch in Python, without relying on external cryptographic libraries.
- 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.
The implementation consists of two main Python files:
- 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
- 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
Run the program to test the implementation:
python main.pyThe program will:
- Let you choose AES version (128/192/256-bit)
- Accept input text for encryption
- Show detailed security information
- Perform encryption and decryption
- Verify the results
| 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) |
- Uses Python's
secretsmodule 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.