Implement a simplified version of the AES (Advanced Encryption Standard) encryption algorithm. Your implementation should include the four main transformation steps:
1. SubBytes: Replace each byte in the state matrix using a substitution box (S-box)
2. ShiftRows: Cyclically shift the rows of the state matrix left
3. MixColumns: Mix the data within each column of the state matrix
4. AddRoundKey: XOR the state matrix with a round key
Given a 4x4 state matrix and a 4x4 round key, perform one round of AES encryption and return the resulting encrypted state matrix.
Note: This is a simplified educational version focusing on the core transformations. Use the provided S-box values for SubBytes transformation.
💡 Note:Apply SubBytes using S-box, shift rows left by 0,1,2,3 positions, mix columns using matrix multiplication, and XOR with round key to get final encrypted state.
💡 Note:Each byte gets substituted via S-box, rows cyclically shift, columns mix through Galois field operations, and final XOR with key produces encrypted result.
a
Amazon 15M
Microsoft 12I
IBM 18GS
Goldman Sachs 8
AES Encryption (Simplified) — Solution
The key insight is understanding that AES encryption applies four distinct transformations sequentially: SubBytes for confusion, ShiftRows and MixColumns for diffusion, and AddRoundKey for key incorporation. Best approach is the optimized in-place implementation. Time: O(1), Space: O(1)
Common Approaches
✓
In-Place Optimized Implementation
⏱️ Time: O(1)
Space: O(1)
Reduce memory overhead by performing all transformations directly on the input matrix without creating intermediate copies, using efficient bit operations and lookup tables.
Step-by-Step Manual Implementation
⏱️ Time: O(1)
Space: O(1)
Implement each of the four AES steps (SubBytes, ShiftRows, MixColumns, AddRoundKey) as separate functions and apply them sequentially to transform the state matrix.