AES Encryption (Simplified) - Problem

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.

Input & Output

Example 1 — Basic AES Round
$ Input: state = [[50,67,246,168],[136,90,48,141],[49,49,152,162],[224,34,76,90]], roundKey = [[43,126,21,22],[40,174,210,166],[171,247,21,136],[9,207,79,60]]
Output: [[124,119,123,242],[107,111,197,48],[168,71,27,20],[138,10,91,109]]
💡 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.
Example 2 — Different Input Values
$ Input: state = [[25,160,154,233],[61,244,198,248],[227,226,141,148],[190,4,86,155]], roundKey = [[162,217,206,182],[113,175,102,207],[208,227,175,230],[16,106,38,235]]
Output: [[46,251,108,142],[242,58,47,15],[209,165,78,134],[93,168,140,212]]
💡 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.
Example 3 — Edge Case with Zero Values
$ Input: state = [[0,0,0,0],[1,1,1,1],[255,255,255,255],[128,128,128,128]], roundKey = [[0,0,0,0],[255,255,255,255],[1,1,1,1],[128,128,128,128]]
Output: [[99,124,119,123],[109,80,232,78],[98,251,108,142],[93,168,140,212]]
💡 Note: Edge case showing behavior with boundary values (0, 1, 255, 128). S-box transforms 0→99, row shifts apply, mix columns processes each value, and AddRoundKey completes encryption.

Constraints

  • 4x4 state matrix with values 0 ≤ state[i][j] ≤ 255
  • 4x4 round key matrix with values 0 ≤ roundKey[i][j] ≤ 255
  • All values represent bytes (0-255 range)
  • Fixed S-box values as per AES specification

Visualization

Tap to expand
INPUTState Matrix (4x4)50672461681369048141Round Key (4x4)431262122ALGORITHM1SubBytesS-box substitution2ShiftRowsCyclic left shift3MixColumnsMatrix multiplication4AddRoundKeyXOR with round keyRESULTEncrypted State12411912324210711119748Key Insight:AES combines substitution (SubBytes), permutation (ShiftRows, MixColumns), and key mixingto create confusion and diffusion - the foundation of secure encryption.TutorialsPoint - AES Encryption (Simplified) | Step-by-Step Implementation
Asked in
Amazon 15 Microsoft 12 IBM 18 Goldman Sachs 8
107.9K Views
Medium Frequency
~35 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen