Skip to main content
IoT
PSUT Engineering StudioPrincess Sumaya University for Technology
Student Edition
Cyber Defense StudioIoT Security and PrivacyExperimentsWorkspaces
Home / IoT Security and Privacy / Cryptography Engineering
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
CRYPTOGRAPHY ENGINEERING · CR18 · AES
IoT Security and Privacy

AES · key expansion

Nk=4,6,8 words.

CR18 · Laboratory mentorAsk about the current operation and its intermediate values.
CR18 · Academic orientation

Scope and objectives

Scope of the experiment

The key schedule expands Nk initial 32-bit words into 4(Nr+1) words. Nk=4,6,8 for the three key lengths. Rcon is successive field powers of x in the first byte.

The focus of this experiment is to trace RotWord, SubWord and Rcon in AES key expansion. Students then calculate selected round-key words for the specified key length, and verify the expansion and explain the extra AES-256 SubWord condition. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.

Learning objectives

  • Trace RotWord, SubWord and Rcon in AES key expansion.
  • Calculate selected round-key words for the specified key length.
  • Verify the expansion and explain the extra AES-256 SubWord condition.
  • Record the relevant inputs, intermediate states and final verification result before changing the reference configuration.
  • Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.

Expected learning outcomes

On completion, students can trace RotWord, SubWord and Rcon in AES key expansion, calculate selected round-key words for the specified key length, and verify the expansion and explain the extra AES-256 SubWord condition.

Required deliverables

Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing verify the expansion and explain the extra AES-256 SubWord condition. Separate predicted values from observations.

Prerequisite knowledge and related learning

Use the curriculum sequence and the Concepts section for prerequisite terminology. After completion, continue to AES · complete cipher and inverse.

Environment and experimental methodology

A standard browser and the experiment-specific Python implementation or Colab notebook. Where the practical uses a protocol model, model results are distinguished from actual local cryptographic operations.

Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.

01 · Experiment overview

CR18 · AES · key expansion

Nk=4,6,8 words. w[i]=w[i−Nk] XOR temp; when i mod Nk=0 use RotWord/SubWord/Rcon; AES-256 additionally SubWord when i mod Nk=4. 44/52/60 words give 11/13/15 round keys.

Before starting

Environment: standard computer, browser and Python/WSL.

Simulation: Editable JavaScript calculation

Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.

Complete the six stages in order. Use the same experiment inputs when comparing manual, browser and Python results.

02 · Concepts and mathematical foundations

Nk=4,6,8 words. w[i]=w[i−Nk] XOR temp; when i mod Nk=0 use RotWord/SubWord/Rcon; AES-256 additionally SubWord when i mod Nk=4. 44/52/60 words give 11/13/15 round keys.

Learning objectives

Calculate the named operation, inspect its intermediate values, reproduce the result in Python, and explain one controlled change. Prerequisites: binary/hexadecimal arithmetic; complete preceding labs in the same topic where applicable.

Before starting

Environment: standard computer, browser and Python/WSL.

Simulation: Editable JavaScript calculation

Technical scope: Classroom computation on a standard computer. Educational cipher code is not a production security implementation.

Key expansion recurrence

1 · Principles and purpose

The key schedule expands Nk initial 32-bit words into 4(Nr+1) words. Nk=4,6,8 for the three key lengths. Rcon is successive field powers of x in the first byte.

2 · Mathematical and algorithmic foundations

temp=w[i−1]; when i mod Nk=0 apply RotWord, SubWord and Rcon XOR. For Nk=8 and i mod Nk=4 apply SubWord only. Then w[i]=w[i−Nk]⊕temp. Four successive words form each round key.

3 · Worked teaching example

For word 09CF4F3C, RotWord=CF4F3C09; SubWord=8A84EB01; first Rcon gives 8B84EB01. XOR with 2B7E1516 gives A0FAFE17. Expansion is deterministic, not random key generation.

Verified default trace · 51 intermediate states

Given parameters (teaching example):

{
  "key": "000102030405060708090A0B0C0D0E0F"
}
StageComputed values
1{ "step": "w[4]", "operation": "RotWord, SubWord, Rcon=01", "base": "00010203", "temp": "D6AB76FE", "word": "D6AA74FD" }
2{ "step": "w[5]", "operation": "XOR previous word", "base": "04050607", "temp": "D6AA74FD", "word": "D2AF72FA" }
3{ "step": "w[6]", "operation": "XOR previous word", "base": "08090A0B", "temp": "D2AF72FA", "word": "DAA678F1" }
4{ "step": "w[7]", "operation": "XOR previous word", "base": "0C0D0E0F", "temp": "DAA678F1", "word": "D6AB76FE" }
5{ "step": "w[8]", "operation": "RotWord, SubWord, Rcon=02", "base": "D6AA74FD", "temp": "6038BBF6", "word": "B692CF0B" }
6{ "step": "w[9]", "operation": "XOR previous word", "base": "D2AF72FA", "temp": "B692CF0B", "word": "643DBDF1" }
7{ "step": "w[10]", "operation": "XOR previous word", "base": "DAA678F1", "temp": "643DBDF1", "word": "BE9BC500" }
8{ "step": "w[11]", "operation": "XOR previous word", "base": "D6AB76FE", "temp": "BE9BC500", "word": "6830B3FE" }
9{ "step": "w[12]", "operation": "RotWord, SubWord, Rcon=04", "base": "B692CF0B", "temp": "006DBB45", "word": "B6FF744E" }
10{ "step": "w[13]", "operation": "XOR previous word", "base": "643DBDF1", "temp": "B6FF744E", "word": "D2C2C9BF" }
11{ "step": "w[14]", "operation": "XOR previous word", "base": "BE9BC500", "temp": "D2C2C9BF", "word": "6C590CBF" }
12{ "step": "w[15]", "operation": "XOR previous word", "base": "6830B3FE", "temp": "6C590CBF", "word": "0469BF41" }
13{ "step": "w[16]", "operation": "RotWord, SubWord, Rcon=08", "base": "B6FF744E", "temp": "F10883F2", "word": "47F7F7BC" }
14{ "step": "w[17]", "operation": "XOR previous word", "base": "D2C2C9BF", "temp": "47F7F7BC", "word": "95353E03" }
15{ "step": "w[18]", "operation": "XOR previous word", "base": "6C590CBF", "temp": "95353E03", "word": "F96C32BC" }
16{ "step": "w[19]", "operation": "XOR previous word", "base": "0469BF41", "temp": "F96C32BC", "word": "FD058DFD" }
17{ "step": "w[20]", "operation": "RotWord, SubWord, Rcon=10", "base": "47F7F7BC", "temp": "7B5D5454", "word": "3CAAA3E8" }
18{ "step": "w[21]", "operation": "XOR previous word", "base": "95353E03", "temp": "3CAAA3E8", "word": "A99F9DEB" }
19{ "step": "w[22]", "operation": "XOR previous word", "base": "F96C32BC", "temp": "A99F9DEB", "word": "50F3AF57" }
20{ "step": "w[23]", "operation": "XOR previous word", "base": "FD058DFD", "temp": "50F3AF57", "word": "ADF622AA" }
21{ "step": "w[24]", "operation": "RotWord, SubWord, Rcon=20", "base": "3CAAA3E8", "temp": "6293AC95", "word": "5E390F7D" }
22{ "step": "w[25]", "operation": "XOR previous word", "base": "A99F9DEB", "temp": "5E390F7D", "word": "F7A69296" }
23{ "step": "w[26]", "operation": "XOR previous word", "base": "50F3AF57", "temp": "F7A69296", "word": "A7553DC1" }
24{ "step": "w[27]", "operation": "XOR previous word", "base": "ADF622AA", "temp": "A7553DC1", "word": "0AA31F6B" }
25{ "step": "w[28]", "operation": "RotWord, SubWord, Rcon=40", "base": "5E390F7D", "temp": "4AC07F67", "word": "14F9701A" }
26{ "step": "w[29]", "operation": "XOR previous word", "base": "F7A69296", "temp": "14F9701A", "word": "E35FE28C" }
27{ "step": "w[30]", "operation": "XOR previous word", "base": "A7553DC1", "temp": "E35FE28C", "word": "440ADF4D" }
28{ "step": "w[31]", "operation": "XOR previous word", "base": "0AA31F6B", "temp": "440ADF4D", "word": "4EA9C026" }
29{ "step": "w[32]", "operation": "RotWord, SubWord, Rcon=80", "base": "14F9701A", "temp": "53BAF72F", "word": "47438735" }
30{ "step": "w[33]", "operation": "XOR previous word", "base": "E35FE28C", "temp": "47438735", "word": "A41C65B9" }
31{ "step": "w[34]", "operation": "XOR previous word", "base": "440ADF4D", "temp": "A41C65B9", "word": "E016BAF4" }
32{ "step": "w[35]", "operation": "XOR previous word", "base": "4EA9C026", "temp": "E016BAF4", "word": "AEBF7AD2" }
33{ "step": "w[36]", "operation": "RotWord, SubWord, Rcon=1B", "base": "47438735", "temp": "13DAB5E4", "word": "549932D1" }
34{ "step": "w[37]", "operation": "XOR previous word", "base": "A41C65B9", "temp": "549932D1", "word": "F0855768" }
35{ "step": "w[38]", "operation": "XOR previous word", "base": "E016BAF4", "temp": "F0855768", "word": "1093ED9C" }
36{ "step": "w[39]", "operation": "XOR previous word", "base": "AEBF7AD2", "temp": "1093ED9C", "word": "BE2C974E" }
37{ "step": "w[40]", "operation": "RotWord, SubWord, Rcon=36", "base": "549932D1", "temp": "47882FAE", "word": "13111D7F" }
38{ "step": "w[41]", "operation": "XOR previous word", "base": "F0855768", "temp": "13111D7F", "word": "E3944A17" }
39{ "step": "w[42]", "operation": "XOR previous word", "base": "1093ED9C", "temp": "E3944A17", "word": "F307A78B" }
40{ "step": "w[43]", "operation": "XOR previous word", "base": "BE2C974E", "temp": "F307A78B", "word": "4D2B30C5" }
41{ "step": "Round key 0", "state": "000102030405060708090A0B0C0D0E0F" }
42{ "step": "Round key 1", "state": "D6AA74FDD2AF72FADAA678F1D6AB76FE" }
43{ "step": "Round key 2", "state": "B692CF0B643DBDF1BE9BC5006830B3FE" }
44{ "step": "Round key 3", "state": "B6FF744ED2C2C9BF6C590CBF0469BF41" }
45{ "step": "Round key 4", "state": "47F7F7BC95353E03F96C32BCFD058DFD" }
46{ "step": "Round key 5", "state": "3CAAA3E8A99F9DEB50F3AF57ADF622AA" }
47{ "step": "Round key 6", "state": "5E390F7DF7A69296A7553DC10AA31F6B" }
48{ "step": "Round key 7", "state": "14F9701AE35FE28C440ADF4D4EA9C026" }
49{ "step": "Round key 8", "state": "47438735A41C65B9E016BAF4AEBF7AD2" }
50{ "step": "Round key 9", "state": "549932D1F08557681093ED9CBE2C974E" }
51{ "step": "Round key 10", "state": "13111D7FE3944A17F307A78B4D2B30C5" }

Recorded result

{
  "round_keys": 11,
  "last": "13111D7FE3944A17F307A78B4D2B30C5"
}

Captured earlier local execution. Randomized values and timing can differ; compare the invariant.

4 · Verification and experimental interpretation

Step through the following visualization and compare the named operation with the corresponding computed state. Check the mathematical invariant, inverse operation or protocol acceptance condition. Change one input at a time; distinguish a measured output from a prediction.

Mathematical representation and interpretation

Key schedule recurrence

w_i is a 32-bit word, N_k is the number of words in the original key (4, 6 or 8). The special cases insert nonlinearity and round-dependent constants.

\[w_i=w_{i-N_k}\oplus t_i,\qquad t_i=\begin{cases}\operatorname{SubWord}(\operatorname{RotWord}(w_{i-1}))\oplus\operatorname{Rcon}_{i/N_k},&i\bmod N_k=0\\\operatorname{SubWord}(w_{i-1}),&N_k=8,\ i\bmod N_k=4\\w_{i-1},&\text{otherwise}\end{cases}\]

Concept animation · AES key expansion

Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.

AES-128 key expansion — 32-bit word constructionw[i−4]00010203RotWord, SubWord, Rcon=01D6AB76FEXORw[4]D6AA74FDEvery fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]04050607XOR previous wordD6AA74FDXORw[5]D2AF72FAEvery fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]08090A0BXOR previous wordD2AF72FAXORw[6]DAA678F1Every fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]0C0D0E0FXOR previous wordDAA678F1XORw[7]D6AB76FEEvery fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]D6AA74FDRotWord, SubWord, Rcon=026038BBF6XORw[8]B692CF0BEvery fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]D2AF72FAXOR previous wordB692CF0BXORw[9]643DBDF1Every fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]DAA678F1XOR previous word643DBDF1XORw[10]BE9BC500Every fourth word applies the nonlinear transformation and Rcon.AES-128 key expansion — 32-bit word constructionw[i−4]D6AB76FEXOR previous wordBE9BC500XORw[11]6830B3FEEvery fourth word applies the nonlinear transformation and Rcon.

Step 1 of 8 · w[4]

Teaching example only; inspect live calculations or real practical evidence separately.

w[4]

operation
RotWord, SubWord, Rcon=01
base
00010203
temp
D6AB76FE
word
D6AA74FD
Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research

03 · Interactive simulation

Baseline diagram loaded. Interactive engine initializing…

Verified baseline reference — use the live workstation below to explore steps and compare inputs.
CR18 w[4]AES key expansion · word recurrencew[3]0C0D0E0FRotWord0D0E0F0CSubWordD7AB76FEXOR Rcon 01000000D6AB76FEw[0]00010203XOR → w[4]D6AA74FDNk = 4; i mod Nk = 0; 11 round keysAES-256 has an additional SubWord branch when i mod 8 = 4.

Edit the fields and choose Recompute. Use step controls to inspect real calculated states. Hexadecimal byte fields are written without 0x; numeric fields accept decimal or 0x notation.

Select an algorithm step to view its calculated diagram. The byte inspector uses index 4c+r; in row/column or XOR labs it jumps to the corresponding operation. Matrix values follow the representation selector; arithmetic annotations use hexadecimal. On narrow screens, scroll the diagram horizontally to inspect every label.

Calculated result

{
  "round_keys": 11,
  "last": "13111D7FE3944A17F307A78B4D2B30C5"
}
All intermediate trace rows

Guided simulation activity

Use the baseline inputs shown above. Predict a result, advance one operation at a time, inspect the intermediate state, then change only the parameter specified in the Experiments view. Export the trace and compare it with your manual derivation.

Continue to practical experiments →

04 · Experiments and engineering investigations

Analytical preparation — before Python

Nk=4,6,8 words. w[i]=w[i−Nk] XOR temp; when i mod Nk=0 use RotWord/SubWord/Rcon; AES-256 additionally SubWord when i mod Nk=4. 44/52/60 words give 11/13/15 round keys.

Predict the baseline result before revealing the calculated state. A controlled comparison changes the named input while keeping the other conditions fixed. Record an observed value separately from an expected value.

Part A · Independent theoretical exercises

Complete each question before running the simulator or Python. Show calculations or protocol traces. The teaching example is a method, not a substitute for the assigned values.

01 · Application and derivation

Application and derivation · Independent work

For the AES-128 key 000102030405060708090A0B0C0D0E0F, split into w0–w3, apply RotWord/SubWord/Rcon to w3 and compute w4 and w5. Identify the condition triggering SubWord in AES-256.

02 · Key schedule

Key schedule · Independent work

For AES-192 and AES-256 calculate total expanded words and the number of round keys. Explain why 192-bit key material is not one 128-bit round key.

Required evidence: state the expected invariant or acceptance condition; record hand-derived results, compare with the simulator or Python trace, and explain the first discrepancy. Do not report a predicted value as a measurement.

Expanded independent theoretical exercise bank

Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.

Intermediate · Alternate configuration

Independent theoretical exercise · CR18-01

For the separate teaching-test configuration key: 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F, predict round_keys using the relevant operation or decision rule. Show intermediate work and state whether this is a deterministic result.

Intermediate · Interpret a computation state

Independent theoretical exercise · CR18-02

A teaching trace for AES · key expansion contains step: w[5]; operation: XOR previous word; base: 04050607; temp: D6AA74FD; word: D2AF72FA. Explain the role of word (recorded value D2AF72FA) and identify the rule or input that determines it. Distinguish an intermediate state from the final result.

Advanced · Identify a terminal invariant

Independent theoretical exercise · CR18-03

The first teaching trace contains step: w[4]; operation: RotWord, SubWord, Rcon=01; base: 00010203; temp: D6AB76FE; word: D6AA74FD; the last contains step: Round key 10; state: 13111D7FE3944A17F307A78B4D2B30C5. Identify one distinction between the initial operation and completion. What additional condition must hold to use the result?

Challenging · Controlled algorithm verification

Independent theoretical exercise · CR18-04

Plan a comparison of key: 000102030405060708090A0B0C0D0E0F with key: 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F. Record the dependent value last, identify the changed factor(s), and describe the verification and failure criterion without claiming a real security measurement.

Part B · Guided simulation and practical procedure

Before starting — tools and setup

Standard computer; extract the WSL toolkit into a new directory. For the browser activity, use the integrated workstation. Editable browser calculation

Install Python dependencies only if required by the selected toolkit README. Use its requirements file and virtual environment instructions.

Open complete, verified WSL commands in Part C ↓

01

Expand words, derive round keys and compare AES variants

  1. Write a prediction using the worked calculation in Concepts.
  2. Load the 16-byte sequential key. Select w[4] and record original word, RotWord, SubWord, Rcon and final XOR. Then select w[5] and round key 1.
  3. Export the trace and compare against the reference only after predicting.

Experimental inputs

Experimental reference · json
{"key":"000102030405060708090A0B0C0D0E0F"}
Verified baseline reference (check after predicting)
Experimental reference · json
{"round_keys":11,"last":"13111D7FE3944A17F307A78B4D2B30C5"}

Compare your baseline with the verified reference output below; for runtime-dependent results, compare invariants and report actual measurements instead of expecting identical timing or randomly generated values.

Evidence to record

Nk, Nr, generated word index, preceding word, temporary word, Rcon, result and round-key count.

Run baseline →
02

Part D · Controlled experiment — Expand words, derive round keys and compare AES variants

  1. Keep the first 16 bytes fixed; extend to 24 and 32 bytes using the sequential suffix. Compare w[Nk], round-key counts, total expanded words and the AES-256 special SubWord step w[12].
  2. Record the conditions held constant and complete the trial table.
  3. Measure Nk, Nr, generated word index, preceding word, temporary word, Rcon, result and round-key count. Explain the first differing operation and verify inverse recovery where applicable.
TrialInput configurationPredictionObservedVerification
1{"key":"000102030405060708090A0B0C0D0E0F"}
2{"key":"000102030405060708090A0B0C0D0E0F1011121314151617"}
3{"key":"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"}

Use the table as a recording template; enter your own measured values in the field below or reproduce it in your report.

Return to simulation →
03

Part E/F · Independent Python verification and deliverables

  1. Download the notebook or toolkit and run the default example.
  2. Reproduce each assigned trial using the notebook or edit a copy of example-input.json and use python3 lab.py --params example-input.json. Compare the browser and Python trace at the same step.
  3. Complete the independent assessment below without copying the worked baseline. Explain discrepancies and distinguish mathematical results from security claims.
Additional investigation instructions

A controlled comparison changes one independent input while holding other inputs fixed, then measures its effect on the dependent output. A baseline is the unmodified run. Evidence-based reasoning means citing the actual observed values, not merely asserting that an algorithm is secure.

  1. Run the supplied default values and record the first and final state.
  2. Predict the effect before changing anything. Change extend key to 24 and 32 bytes. First verified alternate: {"key": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"}.
  3. Keep initial 16 key bytes.
  4. Measure temp, base word, generated word and key count.
  5. Restore the baseline and repeat with another valid input. Locate the first differing calculation.
  6. Submit a comparison table, a trace JSON or screenshots of relevant steps, and a short conclusion with an explicit limitation.
TrialChanged inputFixed conditionsPredictionMeasured valueReason / limitation
BaselineNoneDefaultStudent predictionRecord traceExplain
Trial 1Specified changeUnchanged inputsStudent predictionRecord traceExplain

Part C · Python, Google Colab and WSL

The standalone implementation uses the same synthetic baseline and calculations as the browser. In Colab, download the notebook, open Colab and upload it using File → Upload notebook. Run all cells in order.

WSL / Linux execution workflow

Use Ubuntu or Kali WSL, not PowerShell. Download the toolkit above to your computer. If Python, venv or unzip is missing, install these prerequisites once (requires administrator permission and network access).

Optional prerequisites · bash
sudo apt update
sudo apt install -y python3 python3-venv unzip

In WSL, enter the actual downloaded ZIP path when prompted (for example, a file under /mnt/c/Users/…/Downloads). Extract to a new, dedicated directory. If this directory already exists from a previous extraction, use the existing verified toolkit or choose a clean directory rather than overwriting it.

Step 1 · Extract · bash
read -r -p "Full path to PSUT_V22_9_9_Cryptography_WSL.zip: " ZIP
DEST="$HOME/psut-crypto-v22.9.9"
if [ -f "$ZIP" ] && [ ! -e "$DEST" ]; then
    mkdir "$DEST" && unzip "$ZIP" -d "$DEST"
else
    echo "Check ZIP path and use a fresh destination."
fi

Create the isolated environment in the extracted toolkit root, activate it, then enter this experiment’s actual folder. Install only its declared dependencies. A comment-only requirements file requires no third-party packages.

Step 2 · Activate and install · bash
cd ~/psut-crypto-v22.9.9
python3 -m venv .venv
source .venv/bin/activate
cd CR18
ls
python -m pip install -r requirements.txt

Execute the default run and save the genuine program output. Then run the supplied regression test and the baseline fixture through the explicit input interface.

Step 3 · Run and verify · bash
python lab.py | tee my-results.json
python test_lab.py
python lab.py --params example-input.json
python -m json.tool my-results.json

To change inputs, copy example-input.json, edit the copy in a text editor and run the command below. The original fixture is preserved.

Step 4 · Change an input · bash
cp example-input.json my-input.json
# Edit my-input.json with your preferred editor.
python lab.py --params my-input.json

These scripts terminate normally. Use Ctrl+C to stop a long-running calculation if needed. When finished, leave the isolated virtual environment; no global service cleanup is required for these local examples.

Step 5 · Finish · bash
deactivate

Declared dependencies: # Standard library only for core experiment

Expected terminal output — captured local execution

This excerpt contains the actual first trace step and final result from python lab.py, followed by the actual regression test output. Full stdout is in CR18/verified-output.txt inside the toolkit. Timing, random signatures, keys, certificate fields and implementation-dependent sizes can vary; compare the invariant and record your own observations.

Verified execution excerpt · text
{
  "first_step": {
    "step": "w[4]",
    "operation": "RotWord, SubWord, Rcon=01",
    "base": "00010203",
    "temp": "D6AB76FE",
    "word": "D6AA74FD"
  },
  "result": {
    "round_keys": 11,
    "last": "13111D7FE3944A17F307A78B4D2B30C5"
  }
}

Test script output:
PASS

Check the output JSON and the test exit status. An assertion error means the expected invariant was not met. If Python reports a missing module, activate the environment and install the experiment’s requirements file; if a file is missing, check pwd and ls.

Inspect the documented Python implementation
Documented Python implementation · python
# ============================================================
# CR18 | Educational implementation and trace functions
# Copyright © 2026/2027 Dr. Mohammad Alja’afreh
# PSUT IoT Engineering Studio | Educational, synthetic inputs
# ============================================================
from functools import lru_cache

# Multiply binary polynomials by XORing shifted copies; no integer carries.
def pmul(a,b):
    r=0
    for i in range(b.bit_length()):
        if b>>i&1: r ^= a<<i
    return r

# Cancel the leading polynomial term repeatedly, retaining quotient and remainder.
def pdiv(a,b):
    if not b: raise ValueError('Zero polynomial divisor')
    q=0; steps=[]
    while a and a.bit_length()>=b.bit_length():
        k=a.bit_length()-b.bit_length(); old=a; q ^= 1<<k; a ^= b<<k
        steps.append((old,b<<k,a))
    return q,a,steps

# Reduce the carry-free product by the selected irreducible polynomial.
def gm(a,b,m=0x11b): return pdiv(pmul(a,b),m)[1]

# Use polynomial extended Euclid to find a multiplicative inverse.
def gi(a,m=0x11b):
    if not a: raise ValueError('Zero has no multiplicative inverse')
    r,s=m,a; t,u=0,1
    while s:
        q,v,_=pdiv(r,s); r,s=s,v; t,u=u,t^pmul(q,u)
    if r!=1: raise ValueError('Not invertible')
    return pdiv(t,m)[1]

def hx(n,w=2): return f'{n:0{w}X}'

# Wrap shifted bits around the fixed word width instead of discarding them.
def rot(x,k,w): return ((x<<k)|(x>>(w-k)))&((1<<w)-1)

def xor(a,b): return bytes(x^y for x,y in zip(a,b))

def hexs(a): return bytes(a).hex().upper()

def row(label,**values): return {'step':label,**values}

# Compute the public AES substitution from a field inverse and affine transform.
@lru_cache(maxsize=256)
def sb(a):
    v=gi(a) if a else 0
    return v^rot(v,1,8)^rot(v,2,8)^rot(v,3,8)^rot(v,4,8)^0x63

# Generate all round words using Nk-dependent transformations and Rcon.
def expand(key):
    nk=len(key)//4
    if len(key) not in (16,24,32): raise ValueError('AES key must be 16, 24 or 32 bytes')
    w=[key[i:i+4] for i in range(0,len(key),4)]; trace=[]; rc=1
    for i in range(nk,4*(nk+7)):
        t=w[-1]; operation='XOR previous word'
        if i%nk==0:
            t=bytes(sb(x) for x in t[1:]+t[:1]); t=xor(t,bytes([rc,0,0,0])); operation=f'RotWord, SubWord, Rcon={hx(rc)}'; rc=gm(rc,2)
        elif nk==8 and i%nk==4: t=bytes(sb(x) for x in t); operation='SubWord'
        w.append(xor(w[i-nk],t)); trace.append(row(f'w[{i}]',operation=operation,base=hexs(w[i-nk]),temp=hexs(t),word=hexs(w[i])))
    return [b''.join(w[i:i+4]) for i in range(0,len(w),4)],trace

def n(s): return int(s,0)

def b(s): return bytes.fromhex(s)

def pack(result,trace): return {'result':result,'trace':trace}

EXTRA = {}

def run(p):
    k=b(p['key']);ks,t=expand(k);return pack({'round_keys':len(ks),'last':hexs(ks[-1])},t+[row(f'Round key {i}',state=hexs(x)) for i,x in enumerate(ks)])

PARAMS = {'key': '000102030405060708090A0B0C0D0E0F'}
EXPECTED = {'round_keys': 11, 'last': '13111D7FE3944A17F307A78B4D2B30C5'}
ALT = {'key': '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'}
ALT_EXPECTED = {'round_keys': 15, 'last': '24FC79CCBF0979E9371AC23C6D68DE36'}

if __name__ == "__main__":
    import argparse, json
    parser=argparse.ArgumentParser(description="CR18 synthetic cryptography exercise")
    parser.add_argument("--params", help="JSON parameter override file")
    parser.add_argument("--test", action="store_true")
    args=parser.parse_args()
    if args.test:
        assert run(PARAMS)["result"] == EXPECTED
        assert run(ALT)["result"] == ALT_EXPECTED
        print("CR18 default and changed input passed")
    else:
        parameters=PARAMS if not args.params else {**PARAMS,**json.load(open(args.params))}
        print(json.dumps(run(parameters),indent=2))
Verified default result
Reference result · json
{
  "round_keys": 11,
  "last": "13111D7FE3944A17F307A78B4D2B30C5"
}

05 · Interactive flashcards

Recall before revealing. Review and mastery ratings remain on this device.

Browse all explanations
Why does AES-256 require an extra SubWord branch?

Its standard key schedule specifies it at i mod 8=4.

What is the dependent variable in this lab?

temp, base word, generated word and key count

What must remain controlled?

initial 16 key bytes

What input settings define the baseline for this experiment?

key = 000102030405060708090A0B0C0D0E0F

What is the first intermediate state in the baseline?

step: w[4]; operation: RotWord, SubWord, Rcon=01; base: 00010203; temp: D6AB76FE; word: D6AA74FD

How many words does AES-192 produce?

52 words, or 13 round keys.

What is the first Rcon word?

01000000.

Why do round keys contain four words even for AES-256?

The AES state is always four columns of four bytes.

06 · Knowledge assessment

Formative check

What is applied at w[12] for AES-256?

Responses are for instructor review; no grading key is provided here.

Independent assessment

Expand the 24-byte key 000102030405060708090A0B0C0D0E0F1011121314151617. Derive w[6] and w[7] explicitly and identify which later word first uses the second Rcon. Use an additional valid trial, a calculation or a counterexample to support your reasoning. Submit evidence from both runtimes and explain what the experiment does not establish.

Part F · Engineering evidence record

Record the baseline, prediction, changed input, observed result, discrepancy and limitation. Save locally or export with the displayed result. This is not an official submission.

All Cryptography Engineering labsNext laboratory · CR19 →

How to investigate · CR18

Independent variable: extend key to 24 and 32 bytes.

Controlled variables: initial 16 key bytes.

Dependent evidence: temp, base word, generated word and key count.

Weak conclusion: “The output changed.” Stronger reasoning: cite both measured values, name the transformation responsible, and state why the observation does or does not generalize.

Dr. Mohammad · CR18

Offline, deterministic, current-step tutoring. No external AI service or real hardware access.