Skip to main content
IoT
PSUT Engineering StudioPrincess Sumaya University for Technology
V21.6.5 · Student / connected
Cyber Defense StudioIoT Security and PrivacyExperimentsWorkspaces
Continue to CR21–CR27 — five modes and XTS →

V22.7 · Interactive algorithms, Python notebooks and WSL resources

Home / IoT Security and Privacy / EC12
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
ESSENTIAL LABORATORY · EC12 · IoT SECURITY AND PRIVACY
IoT Security and Privacy

AES modes — ECB, CBC, padding, password derivation and encrypted files

Compare block modes, verify decryption and file layout, derive keys from passwords, and recover an encrypted training image.

Design experiment & verify evidence →
EC12 · Laboratory mentorAsk about the current experiment, its algorithms or Python notebook.
Ask Dr. MohammadAdaptive practice
EC12 · Academic orientation

Scope and objectives

Scope of the experiment

Compare block modes, verify decryption and file layout, derive keys from passwords, and recover an encrypted training image.

The focus of this experiment is to compare ECB and CBC, padding and password-based key derivation. Students then trace block recovery and encrypted-file handling, and verify correct and incorrect password or integrity conditions without treating CBC alone as AEAD. 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

  • Compare ECB and CBC, padding and password-based key derivation.
  • Trace block recovery and encrypted-file handling.
  • Verify correct and incorrect password or integrity conditions without treating CBC alone as AEAD.
  • 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 compare ECB and CBC, padding and password-based key derivation, trace block recovery and encrypted-file handling, and verify correct and incorrect password or integrity conditions without treating CBC alone as AEAD.

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 correct and incorrect password or integrity conditions without treating CBC alone as AEAD. Separate predicted values from observations.

Prerequisite knowledge and related learning

Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to K01 · Environment & scope.

Environment and experimental methodology

The included teaching workstation and the listed Python/Colab or WSL implementation. Historical and small-number constructions are instructional, not deployment recommendations.

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.

How to investigate AES modes — ECB, CBC, padding, password derivation and encrypted files

Compare block modes, verify decryption and file layout, derive keys from passwords, and recover an encrypted training image.

Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.

Experiment-specific guided practice

Objective: Compare block modes, verify decryption and file layout, derive keys from passwords, and recover an encrypted training image.

  1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
  2. ECB versus CBC — complete its numbered steps and record the requested evidence.
  3. Padding and classroom binary exchange — complete its numbered steps and record the requested evidence.
  4. Password derivation and file recovery — complete its numbered steps and record the requested evidence.

Reference check: ECB yields identical ciphertext for identical aligned blocks; CBC with distinct chaining values differs. Correct KDF/IV and unpadding recover exactly the original bytes.

Model boundary: Fictional educational inputs. Browser algorithms and reference programs; no hardware or live-network measurements. Supplied starter notebooks may be incomplete; trace playback is recorded execution, not arbitrary Python running in browser.

Independent task and submission evidence

2. ECB versus CBC — complete its numbered steps and record the requested evidence. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.

Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.

TrialChanged settingFixed settingsPredicted resultActual observation / unitsEvidence / uncertainty
A: baselineReferenceRecordPredictRecordRecord
B: one changeRecordSame as APredictRecordRecord
A: repeatRestoreSame as APredictRecordRecord

Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.

Scientific concepts and engineering principles

Scientific architecture · EC12 · AES modes — ECB, CBC, padding, password derivation and encrypted files

ECB vs CBC and file envelope — Split padded plaintext / 16-byte blocks; ECB / encrypt blocks independently; CBC / XOR previous ciphertext or IV; PBKDF2 / derive key with salt & iterations; File envelope / store IV and metadata; authentication needed
Scientific concept map: Plaintext — Block padding; ECB — Independent blocks; CBC — XOR previous ciphertext; PBKDF2 — Salt + iterations; File envelope — IV and ciphertext.

Block modes

AES operates on 16-byte blocks. ECB encrypts each block independently and leaks equality of repeated blocks. CBC XORs each plaintext block with the preceding ciphertext, starting with an unpredictable IV; it needs padding for unaligned data and separate integrity protection.

Padding and binary representation

PKCS#7 appends bytes whose value equals the padding length, including a full block when the message is already aligned. Base64 transports bytes as text without adding confidentiality. Decrypt using the matching key, IV and mode, then remove padding and check the entire plaintext.

Password-derived keys and files

PBKDF2 derives key material from a password, random salt, PRF and iteration count. Save the salt and IV in a documented envelope so the receiver can reconstruct the key and decrypt. The lab fixture uses a fixed documented configuration for reproducibility; deployed systems need authenticated encryption and appropriately tuned KDF parameters.

Prerequisites: EC11 and earlier foundations as applicable.

EC12 engineering diagram
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.

Engineering diagrams

CBC chaining and IV dependency.
CBC chaining and IV dependency.

Scientific foundations and worked examples

Mode equations and repeated blocks

ECB uses \(C_{i}\)=\(E_{k}\)(\(P_{i}\)); equal plaintext blocks produce equal ciphertext blocks. CBC uses \(C_{i}\)=\(E_{k}\)(\(P_{i}\) XOR \(C_{i-1}\)), with \(C_{0}\)=IV. Decrypt by \(P_{i}\)=\(D_{k}\)(\(C_{i}\)) XOR \(C_{i-1}\). CBC needs an unpredictable fresh IV; its secrecy is not required. ECB and CBC require complete blocks; PKCS#7 appends n copies of the byte n, including a whole extra block for already aligned data. Neither mode inherently authenticates ciphertext.

Binary serialization, passwords and file formats

Base64 represents bytes as printable text; it provides no secrecy. PBKDF2 derives a key from password, salt, iteration count, PRF and output length. Random salt prevents reuse of precomputed guesses, not weak passwords. To reproduce a file key, record every KDF parameter. For an IV||salt||ciphertext format with 16-byte IV and salt, bytes 0–15 and 16–31 are header fields and the remaining bytes are ciphertext. Recover using the exact agreed KDF and padding; do not guess omitted parameters. Modern file protection uses authenticated encryption and authenticates format metadata.

Controlled comparison and sharing

Use the same laboratory key and plaintext across mode comparisons; vary the IV alone to isolate its effect. In a peer exchange encode key, IV and ciphertext separately for the classroom exercise and verify decoding before decrypting. A real system must not send a secret key through the same unprotected channel. Use authenticated key exchange or a properly authenticated public key instead.

Engineering principles · additional worked teaching example

CBC chains each block via XOR with previous ciphertext, using an unpredictable IV. PKCS#7 padding appends n bytes each equal to n; for 16-byte blocks and 13 data bytes, append 03 03 03. CBC alone does not authenticate ciphertext; use a suitable authenticated scheme for real applications.

From theory to experiment

Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.

Worked engineering reasoning and boundary conditions

ECB encrypts blocks independently; CBC chains XOR with previous ciphertext; CTR uses unique nonce/counter streams. PKCS#7 appends padding even for aligned data. AEAD provides integrity with confidentiality.

Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.

Concept animation · operation pathway

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 modes — ECB, CBC, padding, password derivation and encrypted files: operation pathwayPlaintext length31 bytesPadone byte 01CBC chainC1=E(P1 XOR IV)Validatedecrypt andauthenticate beforeuseRead the active operation, then inspect the accumulated state.

Step 1 of 4 · Plaintext length

Plaintext length

Plaintext length
31 bytes

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

Interactive flashcards

Self-rated study progress is stored locally, not used for official grades.

Browse all explanations
What leaks in ECB?

Equal plaintext blocks produce equal ciphertext blocks under one key.

Why randomize CBC IV?

To prevent deterministic first-block encryption.

What does PBKDF2 do?

Derives a key from a password with salt and iteration cost.

Does CBC padding authenticate data?

No; use authenticated encryption or proper authentication.

Why does ECB reveal repeated plaintext blocks?

Identical blocks under the same key yield identical ciphertext blocks.

What does CBC XOR before block encryption?

The preceding ciphertext block, or IV for the first block.

What is PKCS#7 padding for a full AES block?

An additional 16-byte block with each byte 0x10.

Why use a random CBC IV?

To avoid predictable first-block encryption patterns.

Is Base64 encryption?

No, it is reversible encoding.

What does a PBKDF2 salt accomplish?

It prevents reuse of precomputed password-derived keys across different salts.

What parameters must match to reproduce PBKDF2?

Password encoding, salt, PRF, iteration count and derived key length.

Does CBC alone authenticate a file?

No.

Why distinguish the replacement image fixture from the model?

The original KDF parameters were incomplete.

What should be checked after file decryption?

Padding, expected file format and authenticated integrity where available.

Why do identical plaintext blocks under ECB often reveal structure?

The same key encrypts identical blocks to identical ciphertext blocks.

If the final plaintext exactly fills the AES block, how many PKCS#7 padding bytes are appended?

A full 16-byte padding block; each byte has value 0x10.

Which parameters are required to reproduce a password-derived encryption key?

Password encoding, KDF, salt, iteration/work factor, PRF, output length and any other KDF-specific settings.

Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research