IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
CRYPTOGRAPHY ENGINEERING · CR23 · MODES
IoT Security and Privacy
AES-CFB · block processing and errors
Encrypt the feedback register and XOR its leading s bytes with the segment.
CR23 · Laboratory mentorAsk about the current operation and its intermediate values.
CR23 · Academic orientation
Scope and objectives
Scope of the experiment
CFB turns a block cipher into a segment-oriented stream construction. The shift register contains the IV initially and thereafter ciphertext segments; encryption and decryption both use E_K.
The focus of this experiment is to trace CFB keystream segments and ciphertext-register feedback. Students then compare segment sizes and error propagation, and verify receiver recovery with the same encryption primitive. 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 CFB keystream segments and ciphertext-register feedback.
Compare segment sizes and error propagation.
Verify receiver recovery with the same encryption primitive.
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 CFB keystream segments and ciphertext-register feedback, compare segment sizes and error propagation, and verify receiver recovery with the same encryption primitive.
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 receiver recovery with the same encryption primitive. 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-OFB · block processing and errors.
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
CR23 · AES-CFB · block processing and errors
CFB encrypts a 128-bit feedback register and XORs the leading s bytes of its output with input. Both encryption and decryption use the AES encryption primitive; append ciphertext, not plaintext, to the shifted register. The segment length s is in bytes here (1–16). CFB does not require block padding and its IV must be unpredictable.
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
CFB encrypts a 128-bit feedback register and XORs the leading s bytes of its output with input. Both encryption and decryption use the AES encryption primitive; append ciphertext, not plaintext, to the shifted register. The segment length s is in bytes here (1–16). CFB does not require block padding and its IV must be unpredictable.
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.
Cipher feedback
1 · Principles and purpose
CFB turns a block cipher into a segment-oriented stream construction. The shift register contains the IV initially and thereafter ciphertext segments; encryption and decryption both use E_K.
2 · Mathematical and algorithmic foundations
\(Z_{i}\)=MSB_s(E_K(\(R_{i}\))); \(C_{i}\)=\(P_{i}\)⊕\(Z_{i}\); \(R_{i+1}\)=LSB_(b−s)(\(R_{i}\))||\(C_{i}\). Decryption computes \(P_{i}\)=\(C_{i}\)⊕\(Z_{i}\) and shifts in received ciphertext.
With segment size 8, keystream byte 0x50 and plaintext 0x6B, ciphertext=0x3B; the register shifts left eight bits and appends 3B. Corrupted ciphertext affects its segment and later register-dependent segments until it shifts out.
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
CFB register update
R_i is the 128-bit register, s is segment size in bits. Decryption uses the same keystream and feeds back ciphertext, not recovered plaintext.
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.
Step 1 of 3 · Block/segment 1
Teaching example only; inspect live calculations or real practical evidence separately.
Block/segment 1
input
6BC1BEE22E409F96E93D7E117393172A
register
000102030405060708090A0B0C0D0E0F
cipher_input
6BC1BEE22E409F96E93D7E117393172A
keystream
50FE67CC996D32B6DA0937E99BAFEC60
output
3B3FD92EB72DAD20333449F8E83CFB4A
next_register
3B3FD92EB72DAD20333449F8E83CFB4A
Block/segment 2
input
6BC1BEE22E409F96E93D7E117393172A
register
3B3FD92EB72DAD20333449F8E83CFB4A
cipher_input
6BC1BEE22E409F96E93D7E117393172A
keystream
668BCF60BEB005A35354A201DAB36BDA
output
0D4A718290F09A35BA69DC10A9207CF0
next_register
0D4A718290F09A35BA69DC10A9207CF0
Block/segment 3
input
6BC1BEE22E409F96E93D7E117393172A
register
0D4A718290F09A35BA69DC10A9207CF0
cipher_input
6BC1BEE22E409F96E93D7E117393172A
keystream
11E0ADBC9231E13DD8436E69D9F314CC
output
7A21135EBC717EAB317E1078AA6003E6
next_register
7A21135EBC717EAB317E1078AA6003E6
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research
Verified baseline reference — use the live workstation below to explore steps and compare inputs.
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 a step to inspect the current calculation. The blue workbench matches the established instrument palette. Exact numeric values are also listed in the trace; scroll diagrams horizontally on narrow displays.
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.
Encrypt the feedback register and XOR its leading s bytes with the segment. Shift register and append ciphertext for both encryption and decryption. Use unpredictable IV; segment length in this lab is measured in bytes (1–16). Errors propagate until bad ciphertext shifts out. Confidentiality only; does not authenticate data.
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 CFB-8, sketch the first two feedback-register states and compute the first ciphertext byte using the first keystream byte. Explain how the shift register incorporates ciphertext and why decryption also uses the encryption function.
Application and derivation — \(Z_{i}\)=MSB_s(E_K(\(R_{i}\))); \(C_{i}\)=\(P_{i}\)⊕\(Z_{i}\); \(R_{i+1}\)=LSB_(b−s)(\(R_{i}\))||\(C_{i}\). Decryption computes \(P_{i}\)=\(C_{i}\)⊕\(Z_{i}\) and shifts in received ciphertext. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Feedback tracing
Feedback tracing · Independent work
In CFB-8, register ends with 0xAA, keystream first byte 0x3E and plaintext 0xB0. Compute ciphertext and register update rule.
Feedback tracing — Review the defining equations and compare the input restrictions and state transitions in Concepts. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
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 · CR23-01
For the separate teaching-test configuration plaintext: 6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A; key: 2B7E151628AED2A6ABF7158809CF4F3C; iv: 000102030405060708090A0B0C0D0E0F; flip_byte: 16; segment: 16, predict length 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 · CR23-02
A teaching trace for AES-CFB · block processing and errors contains step: Block/segment 2; input: 6BC1BEE22E409F96E93D7E117393172A; register: 3B3FD92EB72DAD20333449F8E83CFB4A; cipher_input: 6BC1BEE22E409F96E93D7E117393172A; keystream: 668BCF60BEB005A35354A201DAB36BDA. Explain the role of next_register (recorded value 0D4A718290F09A35BA69DC10A9207CF0) 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 · CR23-03
The first teaching trace contains step: Block/segment 1; input: 6BC1BEE22E409F96E93D7E117393172A; register: 000102030405060708090A0B0C0D0E0F; cipher_input: 6BC1BEE22E409F96E93D7E117393172A; keystream: 50FE67CC996D32B6DA0937E99BAFEC60; output: 3B3FD92EB72DAD20333449F8E83CFB4A; next_register: 3B3FD92EB72DAD20333449F8E83CFB4A; the last contains step: Tamper; byte: 0; changed_bits: [1, 58, 0]. 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 · CR23-04
Plan a comparison of plaintext: 6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A; key: 2B7E151628AED2A6ABF7158809CF4F3C; iv: 000102030405060708090A0B0C0D0E0F; flip_byte: 0; segment: 16 with plaintext: 6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A6BC1BEE22E409F96E93D7E117393172A; key: 2B7E151628AED2A6ABF7158809CF4F3C; iv: 000102030405060708090A0B0C0D0E0F; flip_byte: 16; segment: 16. Record the dependent value error_bits_by_block, 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.
Write a prediction using the worked calculation in Concepts.
Trace CFB-128 step 1 and step 2. Record the register, first 16 keystream bytes and ciphertext; verify the next register equals \(C_{1}\). Inspect inverse and Tamper steps.
Export the trace and compare against the reference after recording your prediction.
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
Segment size, register update, first ciphertext byte, number of steps, and changed bits in recovered 16-byte groups.
Part D · Controlled experiment — Compare CFB-128 and CFB-8 feedback
Run segment=1 and segment=4 separately, holding key, IV, message and flip_byte fixed. Record number of segments, first updated register and per-16-byte-group error counts. Then compare with the baseline.
Record all fixed settings and complete the trial table.
Measure Segment size, register update, first ciphertext byte, number of steps, and changed bits in recovered 16-byte groups. Compare against the baseline and explain the mechanism.
Part E/F · Independent Python verification and deliverables
Download the notebook or toolkit and run the default example.
Run each assigned trial in the notebook or edit a copy of example-input.json and use python3 lab.py --params example-input.json. Compare the exact corresponding states.
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.
Run the supplied default values and record the first and final state.
Predict the effect before changing anything. Change flip_byte 0 to 16; change one byte of plaintext. First verified alternate: {"flip_byte": "16"}.
Keep key and IV/counter; keep segment fixed unless investigating CFB.
Measure each block/segment, register, ciphertext, recovered block and tamper distance.
Restore the baseline and repeat with another valid input. Locate the first differing calculation.
Submit a comparison table, a trace JSON or screenshots of relevant steps, and a short conclusion with an explicit limitation.
Trial
Changed input
Fixed conditions
Prediction
Measured value
Reason / limitation
Baseline
None
Default
Student prediction
Record trace
Explain
Trial 1
Specified change
Unchanged inputs
Student prediction
Record trace
Explain
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.
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).
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 CR23
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.
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 CR23/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.
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.
Does CFB error propagation depend on segment size?
Yes; corrupted ciphertext affects the feedback window.
06 · Knowledge assessment
Formative check
Which data enters the CFB register during decryption?
Responses are for instructor review; no grading key is provided here.
Independent assessment
Run CFB with segments of 1, 4 and 16 bytes. For the same flipped ciphertext byte, record which subsequent plaintext bytes differ and explain recovery using register length. 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.