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 · CR19 · AES
IoT Security and Privacy

AES · complete cipher and inverse

Initial AddRoundKey; rounds SubBytes, ShiftRows, MixColumns, AddRoundKey; final omits MixColumns.

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

Scope and objectives

Scope of the experiment

Encryption composes invertible nonlinear, permutation and linear layers with key XOR. Decryption applies inverse transformations in reverse order with matching round keys; equivalent inverse formulations may transform keys.

The focus of this experiment is to trace forward AES rounds and inverse transformations. Students then identify the initial key addition and final-round exception, and verify known-answer encryption and decryption for supported key sizes. 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 forward AES rounds and inverse transformations.
  • Identify the initial key addition and final-round exception.
  • Verify known-answer encryption and decryption for supported key sizes.
  • 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 forward AES rounds and inverse transformations, identify the initial key addition and final-round exception, and verify known-answer encryption and decryption for supported key sizes.

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 known-answer encryption and decryption for supported key sizes. 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 · round-by-round avalanche.

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

CR19 · AES · complete cipher and inverse

Initial AddRoundKey; rounds SubBytes, ShiftRows, MixColumns, AddRoundKey; final omits MixColumns. Inverse begins with last round key, then inverse transformations and reversed keys. FIPS example 001122…EEFF with key 000102…0F gives 69C4…C55A.

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

Initial AddRoundKey; rounds SubBytes, ShiftRows, MixColumns, AddRoundKey; final omits MixColumns. Inverse begins with last round key, then inverse transformations and reversed keys. FIPS example 001122…EEFF with key 000102…0F gives 69C4…C55A.

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.

Complete AES and inverse

1 · Principles and purpose

Encryption composes invertible nonlinear, permutation and linear layers with key XOR. Decryption applies inverse transformations in reverse order with matching round keys; equivalent inverse formulations may transform keys.

2 · Mathematical and algorithmic foundations

Initial XOR, Nr−1 full rounds, final round without MixColumns. Inverse starts with last round key, then InvShiftRows, InvSubBytes and reverse-order round operations. Known-answer tests check exact block/key mappings.

3 · Worked teaching example

Standard AES-128 vector uses plaintext 00112233445566778899AABBCCDDEEFF and key 000102030405060708090A0B0C0D0E0F. Initial XOR=00102030405060708090A0B0C0D0E0F0; ciphertext=69C4E0D86A7B0430D8CDB78070B4C55A. Decryption must recover all 16 original bytes.

Verified default trace · 82 intermediate states

Given parameters (teaching example):

{
  "plaintext": "00112233445566778899AABBCCDDEEFF",
  "key": "000102030405060708090A0B0C0D0E0F"
}
StageComputed values
1{ "step": "Input", "state": "00112233445566778899AABBCCDDEEFF" }
2{ "step": "0 AddRoundKey", "state": "00102030405060708090A0B0C0D0E0F0" }
3{ "step": "1 SubBytes", "state": "63CAB7040953D051CD60E0E7BA70E18C" }
4{ "step": "1 ShiftRows", "state": "6353E08C0960E104CD70B751BACAD0E7" }
5{ "step": "1 MixColumns", "state": "5F72641557F5BC92F7BE3B291DB9F91A" }
6{ "step": "1 AddRoundKey", "state": "89D810E8855ACE682D1843D8CB128FE4" }
7{ "step": "2 SubBytes", "state": "A761CA9B97BE8B45D8AD1A611FC97369" }
8{ "step": "2 ShiftRows", "state": "A7BE1A6997AD739BD8C9CA451F618B61" }
9{ "step": "2 MixColumns", "state": "FF87968431D86A51645151FA773AD009" }
10{ "step": "2 AddRoundKey", "state": "4915598F55E5D7A0DACA94FA1F0A63F7" }
11{ "step": "3 SubBytes", "state": "3B59CB73FCD90EE05774222DC067FB68" }
12{ "step": "3 ShiftRows", "state": "3BD92268FC74FB735767CBE0C0590E2D" }
13{ "step": "3 MixColumns", "state": "4C9C1E66F771F0762C3F868E534DF256" }
14{ "step": "3 AddRoundKey", "state": "FA636A2825B339C940668A3157244D17" }
15{ "step": "4 SubBytes", "state": "2DFB02343F6D12DD09337EC75B36E3F0" }
16{ "step": "4 ShiftRows", "state": "2D6D7EF03F33E334093602DD5BFB12C7" }
17{ "step": "4 MixColumns", "state": "6385B79FFC538DF997BE478E7547D691" }
18{ "step": "4 AddRoundKey", "state": "247240236966B3FA6ED2753288425B6C" }
19{ "step": "5 SubBytes", "state": "36400926F9336D2D9FB59D23C42C3950" }
20{ "step": "5 ShiftRows", "state": "36339D50F9B539269F2C092DC4406D23" }
21{ "step": "5 MixColumns", "state": "F4BCD45432E554D075F1D6C51DD03B3C" }
22{ "step": "5 AddRoundKey", "state": "C81677BC9B7AC93B25027992B0261996" }
23{ "step": "6 SubBytes", "state": "E847F56514DADDE23F77B64FE7F7D490" }
24{ "step": "6 ShiftRows", "state": "E8DAB6901477D4653FF7F5E2E747DD4F" }
25{ "step": "6 MixColumns", "state": "9816EE7400F87F556B2C049C8E5AD036" }
26{ "step": "6 AddRoundKey", "state": "C62FE109F75EEDC3CC79395D84F9CF5D" }
27{ "step": "7 SubBytes", "state": "B415F8016858552E4BB6124C5F998A4C" }
28{ "step": "7 ShiftRows", "state": "B458124C68B68A014B99F82E5F15554C" }
29{ "step": "7 MixColumns", "state": "C57E1C159A9BD286F05F4BE098C63439" }
30{ "step": "7 AddRoundKey", "state": "D1876C0F79C4300AB45594ADD66FF41F" }
31{ "step": "8 SubBytes", "state": "3E175076B61C04678DFC2295F6A8BFC0" }
32{ "step": "8 ShiftRows", "state": "3E1C22C0B6FCBF768DA85067F6170495" }
33{ "step": "8 MixColumns", "state": "BAA03DE7A1F9B56ED5512CBA5F414D23" }
34{ "step": "8 AddRoundKey", "state": "FDE3BAD205E5D0D73547964EF1FE37F1" }
35{ "step": "9 SubBytes", "state": "5411F4B56BD9700E96A0902FA1BB9AA1" }
36{ "step": "9 ShiftRows", "state": "54D990A16BA09AB596BBF40EA111702F" }
37{ "step": "9 MixColumns", "state": "E9F74EEC023020F61BF2CCF2353C21C7" }
38{ "step": "9 AddRoundKey", "state": "BD6E7C3DF2B5779E0B61216E8B10B689" }
39{ "step": "10 SubBytes", "state": "7A9F102789D5F50B2BEFFD9F3DCA4EA7" }
40{ "step": "10 ShiftRows", "state": "7AD5FDA789EF4E272BCA100B3D9FF59F" }
41{ "step": "10 AddRoundKey", "state": "69C4E0D86A7B0430D8CDB78070B4C55A" }
42{ "step": "Decrypt Input", "state": "69C4E0D86A7B0430D8CDB78070B4C55A" }
43{ "step": "Decrypt 10 AddRoundKey", "state": "7AD5FDA789EF4E272BCA100B3D9FF59F" }
44{ "step": "Decrypt 9 InvShiftRows", "state": "7A9F102789D5F50B2BEFFD9F3DCA4EA7" }
45{ "step": "Decrypt 9 InvSubBytes", "state": "BD6E7C3DF2B5779E0B61216E8B10B689" }
46{ "step": "Decrypt 9 AddRoundKey", "state": "E9F74EEC023020F61BF2CCF2353C21C7" }
47{ "step": "Decrypt 9 InvMixColumns", "state": "54D990A16BA09AB596BBF40EA111702F" }
48{ "step": "Decrypt 8 InvShiftRows", "state": "5411F4B56BD9700E96A0902FA1BB9AA1" }
49{ "step": "Decrypt 8 InvSubBytes", "state": "FDE3BAD205E5D0D73547964EF1FE37F1" }
50{ "step": "Decrypt 8 AddRoundKey", "state": "BAA03DE7A1F9B56ED5512CBA5F414D23" }
51{ "step": "Decrypt 8 InvMixColumns", "state": "3E1C22C0B6FCBF768DA85067F6170495" }
52{ "step": "Decrypt 7 InvShiftRows", "state": "3E175076B61C04678DFC2295F6A8BFC0" }
53{ "step": "Decrypt 7 InvSubBytes", "state": "D1876C0F79C4300AB45594ADD66FF41F" }
54{ "step": "Decrypt 7 AddRoundKey", "state": "C57E1C159A9BD286F05F4BE098C63439" }
55{ "step": "Decrypt 7 InvMixColumns", "state": "B458124C68B68A014B99F82E5F15554C" }
56{ "step": "Decrypt 6 InvShiftRows", "state": "B415F8016858552E4BB6124C5F998A4C" }
57{ "step": "Decrypt 6 InvSubBytes", "state": "C62FE109F75EEDC3CC79395D84F9CF5D" }
58{ "step": "Decrypt 6 AddRoundKey", "state": "9816EE7400F87F556B2C049C8E5AD036" }
59{ "step": "Decrypt 6 InvMixColumns", "state": "E8DAB6901477D4653FF7F5E2E747DD4F" }
60{ "step": "Decrypt 5 InvShiftRows", "state": "E847F56514DADDE23F77B64FE7F7D490" }
61{ "step": "Decrypt 5 InvSubBytes", "state": "C81677BC9B7AC93B25027992B0261996" }
62{ "step": "Decrypt 5 AddRoundKey", "state": "F4BCD45432E554D075F1D6C51DD03B3C" }
63{ "step": "Decrypt 5 InvMixColumns", "state": "36339D50F9B539269F2C092DC4406D23" }
64{ "step": "Decrypt 4 InvShiftRows", "state": "36400926F9336D2D9FB59D23C42C3950" }
65{ "step": "Decrypt 4 InvSubBytes", "state": "247240236966B3FA6ED2753288425B6C" }
66{ "step": "Decrypt 4 AddRoundKey", "state": "6385B79FFC538DF997BE478E7547D691" }
67{ "step": "Decrypt 4 InvMixColumns", "state": "2D6D7EF03F33E334093602DD5BFB12C7" }
68{ "step": "Decrypt 3 InvShiftRows", "state": "2DFB02343F6D12DD09337EC75B36E3F0" }
69{ "step": "Decrypt 3 InvSubBytes", "state": "FA636A2825B339C940668A3157244D17" }
70{ "step": "Decrypt 3 AddRoundKey", "state": "4C9C1E66F771F0762C3F868E534DF256" }
71{ "step": "Decrypt 3 InvMixColumns", "state": "3BD92268FC74FB735767CBE0C0590E2D" }
72{ "step": "Decrypt 2 InvShiftRows", "state": "3B59CB73FCD90EE05774222DC067FB68" }
73{ "step": "Decrypt 2 InvSubBytes", "state": "4915598F55E5D7A0DACA94FA1F0A63F7" }
74{ "step": "Decrypt 2 AddRoundKey", "state": "FF87968431D86A51645151FA773AD009" }
75{ "step": "Decrypt 2 InvMixColumns", "state": "A7BE1A6997AD739BD8C9CA451F618B61" }
76{ "step": "Decrypt 1 InvShiftRows", "state": "A761CA9B97BE8B45D8AD1A611FC97369" }
77{ "step": "Decrypt 1 InvSubBytes", "state": "89D810E8855ACE682D1843D8CB128FE4" }
78{ "step": "Decrypt 1 AddRoundKey", "state": "5F72641557F5BC92F7BE3B291DB9F91A" }
79{ "step": "Decrypt 1 InvMixColumns", "state": "6353E08C0960E104CD70B751BACAD0E7" }
80{ "step": "Decrypt 0 InvShiftRows", "state": "63CAB7040953D051CD60E0E7BA70E18C" }
81{ "step": "Decrypt 0 InvSubBytes", "state": "00102030405060708090A0B0C0D0E0F0" }
82{ "step": "Decrypt 0 AddRoundKey", "state": "00112233445566778899AABBCCDDEEFF" }

Recorded result

{
  "ciphertext": "69C4E0D86A7B0430D8CDB78070B4C55A",
  "recovered": "00112233445566778899AABBCCDDEEFF"
}

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

AES state indexing

b_i denotes the serialized block bytes; AES fills columns first. The number of rounds is 10, 12 or 14 for keys of 128, 192 or 256 bits respectively.

\[S_{r,c}=b_{4c+r},\qquad 0\le r,c<4,\qquad N_r\in\{10,12,14\}\]

Concept animation · AES state transformation

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 · complete cipher and inverse: AES state transformationAES column-major state004488CC115599DD2266AAEE3377BBFFHighlighted bytes changed from the preceding recorded state.

Step 1 of 7 · Input

Input

State hex
00112233445566778899AABBCCDDEEFF
Ordering
column-major

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

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.
CR19 1 MixColumnsAES complete cipher · inspect the selected transformationPrevious state6309CDBA536070CAE0E1B7D08C0451E7Current state5F57F71D72F5BEB964BC3BF91592291ASelected operation1 MixColumns02 × 63 in GF(2⁸)C6⊕03 × 53 in GF(2⁸)F5⊕01 × E0 in GF(2⁸)E0⊕01 × 8C in GF(2⁸)8CC6 ⊕ F5 ⊕ E0 ⊕ 8C = 5FRound 1 · 10 encryption rounds · final round omits MixColumns

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

{
  "ciphertext": "69C4E0D86A7B0430D8CDB78070B4C55A",
  "recovered": "00112233445566778899AABBCCDDEEFF"
}
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

Initial AddRoundKey; rounds SubBytes, ShiftRows, MixColumns, AddRoundKey; final omits MixColumns. Inverse begins with last round key, then inverse transformations and reversed keys. FIPS example 001122…EEFF with key 000102…0F gives 69C4…C55A.

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 baseline AES-128 plaintext/key, manually compute initial AddRoundKey and one selected byte through SubBytes and ShiftRows. Identify all standard-round transformations and the one omitted in the final round. Use the simulator only after writing the prediction.

02 · Debugging

Debugging · Independent work

A program includes MixColumns in the final AES encryption round and then compares with a standard known-answer vector. Explain the error and verification plan.

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 · CR19-01

For the separate teaching-test configuration plaintext: 00112233445566778899AABBCCDDEEFF; key: 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F, predict recovered 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 · CR19-02

A teaching trace for AES · complete cipher and inverse contains step: 0 AddRoundKey; state: 00102030405060708090A0B0C0D0E0F0. Explain the role of state (recorded value 00102030405060708090A0B0C0D0E0F0) 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 · CR19-03

The first teaching trace contains step: Input; state: 00112233445566778899AABBCCDDEEFF; the last contains step: Decrypt 0 AddRoundKey; state: 00112233445566778899AABBCCDDEEFF. 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 · CR19-04

Plan a comparison of plaintext: 00112233445566778899AABBCCDDEEFF; key: 000102030405060708090A0B0C0D0E0F with plaintext: 00112233445566778899AABBCCDDEEFF; key: 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F. Record the dependent value recovered, 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

Verify complete AES encryption and inverse transformations

  1. Write a prediction using the worked calculation in Concepts.
  2. Load the baseline. Inspect initial AddRoundKey and every round-1 transformation. Select byte 0 in each step to reproduce its calculation. Locate round 10, confirm no MixColumns, then follow inverse steps to plaintext recovery.
  3. Export the trace and compare against the reference only after predicting.

Experimental inputs

Experimental reference · json
{"plaintext":"00112233445566778899AABBCCDDEEFF","key":"000102030405060708090A0B0C0D0E0F"}
Verified baseline reference (check after predicting)
Experimental reference · json
{"ciphertext":"69C4E0D86A7B0430D8CDB78070B4C55A","recovered":"00112233445566778899AABBCCDDEEFF"}

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

Key size, round count, initial XOR, round-1 state sequence, ciphertext, recovered plaintext, known-answer and library verification.

Run baseline →
02

Part D · Controlled experiment — Verify complete AES encryption and inverse transformations

  1. Keep the plaintext fixed and use the 24- and 32-byte sequential keys. Verify ciphertexts DDA97CA4864CDFE06EAF70A0EC0D7191 and 8EA2B7CA516745BFEAFC49904B496089. Count forward AddRoundKey operations and record final round labels.
  2. Record the conditions held constant and complete the trial table.
  3. Measure Key size, round count, initial XOR, round-1 state sequence, ciphertext, recovered plaintext, known-answer and library verification. Explain the first differing operation and verify inverse recovery where applicable.
TrialInput configurationPredictionObservedVerification
1{"plaintext":"00112233445566778899AABBCCDDEEFF","key":"000102030405060708090A0B0C0D0E0F"}
2{"plaintext":"00112233445566778899AABBCCDDEEFF","key":"000102030405060708090A0B0C0D0E0F1011121314151617"}
3{"plaintext":"00112233445566778899AABBCCDDEEFF","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 key length 16,24,32 bytes. First verified alternate: {"key": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"}.
  3. Keep plaintext.
  4. Measure every intermediate state and recovered plaintext.
  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 CR19
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 CR19/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": "Input",
    "state": "00112233445566778899AABBCCDDEEFF"
  },
  "result": {
    "ciphertext": "69C4E0D86A7B0430D8CDB78070B4C55A",
    "recovered": "00112233445566778899AABBCCDDEEFF"
  }
}

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
# ============================================================
# CR19 | 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

def invsub(a): return next(i for i in range(256) if sb(i)==a)

# Rotate each matrix row while preserving column-major state layout.
def shift(s,inv=False): return bytes(s[4*((i//4+(-1 if inv else 1)*(i%4))%4)+i%4] for i in range(16))

# Multiply each column by the forward or inverse circulant matrix in GF(2^8).
def mix(s,inv=False):
    a=[14,11,13,9] if inv else [2,3,1,1]
    return bytes(gm(s[4*(i//4)+(i%4)%4],a[0])^gm(s[4*(i//4)+(i%4+1)%4],a[1])^gm(s[4*(i//4)+(i%4+2)%4],a[2])^gm(s[4*(i//4)+(i%4+3)%4],a[3]) for i in range(16))

# 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

# Trace each reversible AES stage, omitting MixColumns in the final encryption round.
def aes(p,key,dec=False):
    if len(p)!=16: raise ValueError('Exactly 16-byte AES block')
    keys,_=expand(key); nr=len(keys)-1; s=p; trace=[row('Input',state=hexs(s))]
    def snap(r,name): trace.append(row(f'{r} {name}',state=hexs(s)))
    if not dec:
        s=xor(s,keys[0]); snap(0,'AddRoundKey')
        for r in range(1,nr+1):
            s=bytes(sb(x) for x in s); snap(r,'SubBytes'); s=shift(s); snap(r,'ShiftRows')
            if r<nr: s=mix(s); snap(r,'MixColumns')
            s=xor(s,keys[r]); snap(r,'AddRoundKey')
    else:
        s=xor(s,keys[nr]); snap(nr,'AddRoundKey')
        for r in range(nr-1,-1,-1):
            s=shift(s,True); snap(r,'InvShiftRows'); s=bytes(invsub(x) for x in s); snap(r,'InvSubBytes'); s=xor(s,keys[r]); snap(r,'AddRoundKey')
            if r: s=mix(s,True); snap(r,'InvMixColumns')
    return s,trace

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

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

def exact(s,size):
    v=b(s)
    if len(v)!=size: raise ValueError(f'Expected {size} bytes')
    return v

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

EXTRA = {}

def run(p):
    s=exact(p['plaintext'],16);k=b(p['key']);c,t=aes(s,k);d,u=aes(c,k,True);return pack({'ciphertext':hexs(c),'recovered':hexs(d)},t+[dict(x,step='Decrypt '+x['step']) for x in u])

PARAMS = {'plaintext': '00112233445566778899AABBCCDDEEFF', 'key': '000102030405060708090A0B0C0D0E0F'}
EXPECTED = {'ciphertext': '69C4E0D86A7B0430D8CDB78070B4C55A', 'recovered': '00112233445566778899AABBCCDDEEFF'}
ALT = {'plaintext': '00112233445566778899AABBCCDDEEFF', 'key': '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'}
ALT_EXPECTED = {'ciphertext': '8EA2B7CA516745BFEAFC49904B496089', 'recovered': '00112233445566778899AABBCCDDEEFF'}

if __name__ == "__main__":
    import argparse, json
    parser=argparse.ArgumentParser(description="CR19 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("CR19 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
{
  "ciphertext": "69C4E0D86A7B0430D8CDB78070B4C55A",
  "recovered": "00112233445566778899AABBCCDDEEFF"
}

05 · Interactive flashcards

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

Browse all explanations
Why is the inverse sequence not identical to encryption?

The order and inverse transforms reverse encryption.

What is the dependent variable in this lab?

every intermediate state and recovered plaintext

What must remain controlled?

plaintext

What input settings define the baseline for this experiment?

plaintext = 00112233445566778899AABBCCDDEEFF; key = 000102030405060708090A0B0C0D0E0F

What is the first intermediate state in the baseline?

step: Input; state: 00112233445566778899AABBCCDDEEFF

What is the first AES decryption operation?

XOR the ciphertext with the final round key.

Does passing a known-answer vector prove secure application-level encryption?

No; application security also depends on mode, authentication and key management.

What does the round-1 MixColumns state depend on?

The preceding ShiftRows state, transformed column-by-column in \(\mathrm{GF}(2^{8})\).

06 · Knowledge assessment

Formative check

Which transformation is omitted in the final encryption round?

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

Independent assessment

Run the lecture plaintext and key given in CR20, identify the first round-1 MixColumns state and the last round’s three transformations. Verify the ciphertext using the provider cell with the edited inputs. 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 · CR20 →

How to investigate · CR19

Independent variable: key length 16,24,32 bytes.

Controlled variables: plaintext.

Dependent evidence: every intermediate state and recovered plaintext.

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 · CR19

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