Trace modular addition, rotations, XOR, key expansion and inverse execution.
The focus of this experiment is to trace SPECK addition, rotation and XOR on fixed-width words. Students then calculate modular addition and reverse round operations, and verify reference vectors and explain ARX word-size constraints. 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 SPECK addition, rotation and XOR on fixed-width words.
Calculate modular addition and reverse round operations.
Verify reference vectors and explain ARX word-size constraints.
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 SPECK addition, rotation and XOR on fixed-width words, calculate modular addition and reverse round operations, and verify reference vectors and explain ARX word-size constraints.
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 reference vectors and explain ARX word-size constraints. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the following catalogue prerequisites before starting. After completion, continue to tcpdump — packet capture and protocol filtering.
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.
Rotate, add modulo the word width, XOR the round key and combine with the rotated right word.
Scientific foundations and analytical reasoning
SPECK32/64 uses ARX with ROR7, modular addition, key XOR and ROL2. Addition carries differ from XOR.
Before operating the equipment or executing the program, derive the expected outcome using the required theoretical work in Experiment. Use the diagram to identify the variables and system boundaries.
Scientific theory · ARX round and modular addition
SPECK32/64 uses 16-bit words, 22 rounds, right rotation by 7 and left rotation by 2. Each round computes x′=(ROR7(x)+y mod 2^16) XOR k and y′=ROL2(y) XOR x′. Addition introduces carries while XOR does not. Decryption reverses XOR, addition and rotations in the proper order.
Worked example and engineering interpretation
For x=0000, y=ffff and k=0000, x′=ffff and y′=0000. Separately, ffff+0002 modulo 2^16=0001, whereas ffff XOR 0002=fffd. Verify the reference vector and inverse with the workstations; the small educational configuration is not a modern production recommendation.
Engineering principles · additional worked teaching example
SPECK is an ARX family: modular addition, rotation and XOR. With 8-bit toy addition, 250+10 mod256=4; rotation differs from ordinary shift because discarded bits reenter. Parameters must match selected variant.
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.
How to investigate SPECK — lightweight ARX block cipher
Trace modular addition, rotations, XOR, key expansion and inverse execution.
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.
SPECK ARX structure — complete its numbered steps and record the requested evidence.
Key expansion and reference vector — complete its numbered steps and record the requested evidence.
Controlled comparison with SIMON — complete its numbered steps and record the requested evidence.
Compare observations with the reference checks and submit the required evidence.
Reference check: a86842f2
22 rounds; every word remains 16 bits.
22 round keys.
Decryption recovers original; distance varies.
Model boundary: The supplied lecture contrasts software-oriented SPECK with hardware-oriented SIMON. SPECK32/64 uses two 16-bit words, 22 rounds, right rotation by 7 and left rotation by 2. The round updates x=(ROR7(x)+y mod 2^16) XOR k, then y=ROL2(y) XOR x. Its key schedule uses the same arithmetic operations with a round counter. The detailed SPECK algorithm and reference vector supplement the supplied slides, which focus mainly on SIMON. This small variant is for learning, not production.
Independent task and submission evidence
2. Key expansion and reference vector — 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.
Trial
Changed setting
Fixed settings
Predicted result
Actual observation / units
Evidence / uncertainty
A: baseline
Reference
Record
Predict
Record
Record
B: one change
Record
Same as A
Predict
Record
Record
A: repeat
Restore
Same as A
Predict
Record
Record
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.
SPECK ARX family
SPECK uses addition, rotation and XOR (ARX). SPECK32/64 has two 16-bit data words, four master-key words and 22 rounds. Addition modulo 2^16 involves carry propagation; XOR does not.
Round and inverse
Compute x′=(ROR7(x)+y mod 2^16) XOR k; compute y′=ROL2(y) XOR x′. To invert, recover y=ROR2(y′ XOR x′) and x=ROL7((x′ XOR k)−y mod 2^16). All operations use fixed-width words.
Key schedule and comparison
The key schedule uses related ARX operations with a round counter. Trace the complete sequence before testing encryption and decryption. Compare operation counts and avalanche curves with SIMON under the same word width; do not infer platform performance solely from round counts.
Prerequisites: LC02
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.
Block and key parameter families
Block width (bits)
Supported key widths (bits)
32
64
48
72, 96
64
96, 128
96
96, 144
128
128, 192, 256
Engineering diagrams
SPECK ARX datapath and carry-producing modular addition.
Worked engineering reasoning and boundary conditions
SPECK uses addition modulo 2^w, rotation and XOR (ARX). Inverse rounds reverse operations using subtraction and inverse rotations, with explicit word masking.
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.
Step 1 of 4 · Word addition
Word addition
Word addition
F0 + 35 = 125 hex
Reduce
Word addition
F0 + 35 = 125 hex
Reduce
25 hex mod 256
XOR
Word addition
F0 + 35 = 125 hex
Reduce
25 hex mod 256
XOR
25 XOR 9A = BF
Inverse
Word addition
F0 + 35 = 125 hex
Reduce
25 hex mod 256
XOR
25 XOR 9A = BF
Inverse
BF XOR 9A=25; subtract 35→F0
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 explanationsWhat is ARX?
Addition, rotation and XOR.
How many rounds in SPECK32/64?
22.
How does modular addition differ from XOR?
Carries propagate in addition.
What verifies the inverse?
Decryption recovers the plaintext.
What is the word width of SPECK32/64?
16 bits.
What are the SPECK32/64 data rotation constants?
Right 7 and left 2.
How is the new left word calculated?
ROR7(x) plus y modulo 2^16, XOR the round key.
How is the new right word calculated?
ROL2(y) XOR the new left word.
What is the published plaintext used in the lab?
6574694c.
What is the published reference ciphertext?
a86842f2 with key 1918111009080100.
What operation reverses modular addition?
Modular subtraction.
Why mask after modular addition?
To retain the fixed word width.
What does the key schedule produce?
One round key for every encryption round.
Why compare round counts separately from speed?
Different operations and implementations have different costs.
Evaluate (FFFF + 0002) mod 2¹⁶.
0001 hexadecimal. The carry beyond 16 bits is discarded.
Why does ARX modular addition create a different transformation than XOR?
Addition propagates carries between bit positions; XOR is independent per bit.
Given the output words, which input is recovered first in the SPECK inverse?
Recover y=ROR2(y′ XOR x′), then recover x using modular subtraction followed by ROL7.
Does a smaller round count prove greater performance on every device?
No. It depends on instruction costs, implementation, memory, architecture and measurement conditions.
Virtual laboratory
Change inputs independently, play or step through the calculated states, expand a workstation, and compare your observations. Browser network models do not send or capture real packets.
Independent theoretical exercises
Before the simulation or practical, solve both experiment-specific tasks. List the given inputs, show the intermediate calculation or state trace, identify the expected observation, and state a limitation. Show formulas and intermediate calculations where relevant, or draw the requested state/sequence diagram. These are independent classroom fixtures; where they differ from the reference configuration below, do not treat them as measured values. Compare your predictions with the corresponding experiment afterwards.
01 · Predict and derive using the given inputs
Using x=6574,y=694c,k=0100, calculate each rotation, addition modulo 65536, and new x/y in hex.
Engineering method — SPECK is an ARX family: modular addition, rotation and XOR. With 8-bit toy addition, 250+10 mod256=4; rotation differs from ordinary shift because discarded bits reenter. Parameters must match selected variant. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
For FFFF+0002 compute modular result and compare XOR. Calculate 22 round-key bytes and verify complete reference vector after manual work.
Engineering method — SPECK is an ARX family: modular addition, rotation and XOR. With 8-bit toy addition, 250+10 mod256=4; rotation differs from ordinary shift because discarded bits reenter. Parameters must match selected variant. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Calculation
Calculation · Independent work
For an 8-bit toy operation, rotate 0x81 right by 1 and add 0x40 modulo256. Explain why this is not a full SPECK round.
Calculation — SPECK is an ARX family: modular addition, rotation and XOR. With 8-bit toy addition, 250+10 mod256=4; rotation differs from ordinary shift because discarded bits reenter. Parameters must match selected variant. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Work is saved locally when browser storage is available. Export it for submission; no remote upload or automatic grade is assigned.
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.
Foundational · Apply the principle
Independent theoretical exercise · LC03-01
In an 8-bit illustration, 0xF0+0x35 mod 256 equals?
Intermediate · Calculate or trace
Independent theoretical exercise · LC03-02
ROR8(0x03,1) equals?
Intermediate · Interpret the result
Independent theoretical exercise · LC03-03
Compute 0x25 XOR 0x9A.
Advanced · Analyze a condition
Independent theoretical exercise · LC03-04
Reverse modular addition: x+0x35≡0x25 mod 256.
Advanced · Diagnose or compare
Independent theoretical exercise · LC03-05
Why is XOR not the inverse of modular addition in general?
Challenging · Engineering verification
Independent theoretical exercise · LC03-06
How should a student validate a named SPECK variant?
Activity sequence
Follow the setup commands, then each named activity. The detailed instructions, given values and recording fields appear below.
SPECK ARX structure — complete its numbered steps and record the requested evidence.
Compare observations with the reference checks and submit the required evidence.
Scientific experimental protocol
Research question: Trace modular addition, rotations, XOR, key expansion and inverse execution.
Independent variables: input message or block, key / associated data, selected bit or permutation rounds. Dependent observations: intermediate words, ciphertext, digest, tag and acceptance.
Controls: use the indicated baseline settings, vary one parameter at a time, and record actual results separately from the browser model. For timing comparisons use the same environment and report repetitions.
2. Follow these commands in sequence (Linux/WSL). For browser-only activities, open Simulation first; the code activities are independent.
BASH · Command
python3 speck_demo.py
3. Run the check before changing inputs. Record the exact Python version and any dependency error. Use Python visualizer to inspect the recorded traces; for edited code, generate and import a new trace using the instructions in that tab.
Complete the activities in order. Hold the controlled conditions fixed, record the input and actual output, and compare your observations with an independent calculation or test vector.
01
SPECK ARX structure
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Compare software-oriented SPECK with hardware-oriented SIMON . Select SPECK32/64, two 16-bit words, 22 rounds.
Compute x′=(ROR7(x)+y mod \(2^{16}\)) XOR k, y′=ROL2(y) XOR x′. Observe carries in addition and contrast with XOR.
Evidence to record
Round datapath values.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
02
Key expansion and reference vector
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Enter master key 1918111009080100, plaintext 6574694c. Step all 22 rounds and inspect key schedule, rotations and modular arithmetic.
Verify a86842f2 and decrypt; run speck_demo.py independently.
Experimental inputs and checks
Known-answer check
K=1918111009080100; P=6574694c; C=a86842f2
Evidence to record
Round keys and encryption/decryption equality.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
03
Controlled comparison with SIMON
Open the exact workstation
Choose the relevant tab below, enter the assigned values in the activity steps, then use Step or Play to inspect intermediate calculations. Return to Experiment and record the results before changing the input.
Flip one input bit and compare round Hamming distances with the unchanged key. Repeat for a key-bit change.
Compare operation types and round counts, not claims of measured throughput; measure local Python timing only if environment is controlled.
Evidence to record
Distance graph, round trip and implementation trade-offs.
Verification: Record the baseline and modified input separately, note the observed intermediate values, compare with the assigned calculation, and explain any mismatch. Do not replace observations with expected values.
Trial
Procedure
Reference check
Your observation
Reference
Use key 1918111009080100 and plaintext 6574694c.
a86842f2
Enter result
ARX
Inspect rotation, modular addition and key XOR at each round.
22 rounds; every word remains 16 bits.
Enter result
Key schedule
Change a word and observe generated keys.
22 round keys.
Enter result
Avalanche
Flip one bit; inspect distance and inverse.
Decryption recovers original; distance varies.
Enter result
Analysis and reporting
How does addition introduce nonlinearity? Why is subtraction used in inverse processing? Compare SIMON and SPECK without inferring hardware performance from browser timing.
Record environment, input values, output and deviations; retain traces or PCAP where appropriate. The table is temporary; save your own report.
Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.
Execution scope: The supplied lecture contrasts software-oriented SPECK with hardware-oriented SIMON. SPECK32/64 uses two 16-bit words, 22 rounds, right rotation by 7 and left rotation by 2. The round updates x=(ROR7(x)+y mod 2^16) XOR k, then y=ROL2(y) XOR x. Its key schedule uses the same arithmetic operations with a round counter. The detailed SPECK algorithm and reference vector supplement the supplied slides, which focus mainly on SIMON. This small variant is for learning, not production. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# LC03 · SPECK — lightweight ARX block cipher
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## 1. Scientific objective
Follow the setup commands, then each named activity. The detailed instructions, given values and recording fields appear below.
Complete the analytical worksheet in the portal first. Record your predictions before running this notebook. This notebook is a bounded local computational investigation; use the portal’s separate WSL, hardware or Remix procedure for real interfaces.
02Instructions · Markdown
## Experiment-specific preparation
Trace modular addition, rotations, XOR, key expansion and inverse execution.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. SPECK ARX structure — complete its numbered steps and record the requested evidence.
2. Key expansion and reference vector — complete its numbered steps and record the requested evidence.
3. Controlled comparison with SIMON — complete its numbered steps and record the requested evidence.
4. Compare observations with the reference checks and submit the required evidence.
5. Compare software-oriented SPECK with hardware-oriented SIMON . Select SPECK32/64, two 16-bit words, 22 rounds.
**Evidence:** a86842f2
22 rounds; every word remains 16 bits.
22 round keys.
Decryption recovers original; distance varies.
**Boundary:** The supplied lecture contrasts software-oriented SPECK with hardware-oriented SIMON. SPECK32/64 uses two 16-bit words, 22 rounds, right rotation by 7 and left rotation by 2. The round updates x=(ROR7(x)+y mod 2^16) XOR k, then y=ROL2(y) XOR x. Its key schedule uses the same arithmetic operations with a round counter. The detailed SPECK algorithm and reference vector supplement the supplied slides, which focus mainly on SIMON. This small variant is for learning, not production.
03Instructions · Markdown
## 2. Reference configuration and investigation
1. SPECK ARX structure — complete its numbered steps and record the requested evidence.
2. Key expansion and reference vector — complete its numbered steps and record the requested evidence.
3. Controlled comparison with SIMON — complete its numbered steps and record the requested evidence.
4. Compare observations with the reference checks and submit the required evidence.
Run cells in order; do not substitute model results for physical measurements.
04Instructions · Markdown
## 3. Actual cipher implementation
Use the public teaching vector. This implementation is not hardened for production.
05Instructions · Markdown
### Implementation cell 1
06Python · executable cell
PYTHON · Code cell
# =====================================================================
# LC03 | Code cell 01 | SPECK — lightweight ARX block cipher
# Purpose: Implementation cell 1
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
"""Educational 32/64 SIMON and SPECK. Public test vectors, not production crypto."""
# Set MASK for the next computation or reference condition.
MASK=0xffff
# Set Z for the next computation or reference condition.
Z='11111010001001010110000111001101111101000100101011000011100110'
# Define the reusable operation rol; keep its logic separate from the trial.
def rol(x,n): return ((x<<n)|(x>>(16-n)))&MASK
# =====================================================================
# LC03 | Code cell 02 | SPECK — lightweight ARX block cipher
# Purpose: Implementation cell 2
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Define the reusable operation ror; keep its logic separate from the trial.
def ror(x,n): return rol(x,16-n)
# Define the reusable operation keys; keep its logic separate from the trial.
def keys(kind,key):
k=[int(key[i:i+4],16) for i in range(0,16,4)][::-1]
if kind=='simon':
for i in range(4,32):
t=ror(k[i-1],3)^k[i-3]
t^=ror(t,1)
k.append(0xfffc^int(Z[(i-4)%62])^k[i-4]^t)
return k
l=k[1:]; k=k[:1]
for i in range(21):
l.append(((ror(l[i],7)+k[i])&MASK)^i)
k.append(rol(k[i],2)^l[i+3])
return k
# Define the reusable operation encrypt; keep its logic separate from the trial.
def encrypt(kind,key,plain):
x,y=int(plain[:4],16),int(plain[4:],16)
for k in keys(kind,key):
if kind=='simon':
x,y=y^(rol(x,1)&rol(x,8))^rol(x,2)^k,x
else:
x=((ror(x,7)+y)&MASK)^k
y=rol(y,2)^x
return f'{x:04x}{y:04x}'
# =====================================================================
# LC03 | Code cell 03 | SPECK — lightweight ARX block cipher
# Purpose: Implementation cell 3
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Define the reusable operation decrypt; keep its logic separate from the trial.
def decrypt(kind,key,cipher):
x,y=int(cipher[:4],16),int(cipher[4:],16)
for k in reversed(keys(kind,key)):
if kind=='simon':
x,y=y,x^(rol(y,1)&rol(y,8))^rol(y,2)^k
else:
old_y=ror(y^x,2)
x=rol(((x^k)-old_y)&MASK,7)
y=old_y
return f'{x:04x}{y:04x}'
# =====================================================================
# LC03 | Code cell 04 | SPECK — lightweight ARX block cipher
# Purpose: 4. Reference encryption and inverse check
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Prepare key; retain only the scope required for this trial.
key='1918111009080100'
# Set plain for the next computation or reference condition.
plain='6574694c'
# Set cipher for the next computation or reference condition.
cipher=encrypt('speck',key,plain)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert cipher=='a86842f2'
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert decrypt('speck',key,cipher)==plain
print(cipher)
# =====================================================================
# LC03 | Code cell 05 | SPECK — lightweight ARX block cipher
# Purpose: 5. Controlled variation
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Compare one-bit input changes, using the same public test key.
changed=f"{int(plain,16)^1:08x}"
# Set other for the next computation or reference condition.
other=encrypt('speck',key,changed)
print("Changed bits:",(int(cipher,16)^int(other,16)).bit_count())
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert decrypt('speck',key,other)==changed
## Experimental analysis and submission
1. Record the reference input, predicted output and actual result.
2. Modify one independent variable and run the relevant cells again.
3. Explain the result using the theory and identify model limitations.
4. Save the notebook with outputs and retain the separate theoretical worksheet.
**Your derivation and conclusion:**
(Complete independently.)
16Instructions · Markdown
## Guided reasoning and evidence
A controlled comparison changes one independent input while keeping the other relevant inputs fixed; the dependent variable is the recorded output. Use this lab’s reference condition above.
**Independent task:** 2. Key expansion and reference vector — 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.
| Trial | Input/configuration | Prediction | Observation | Evidence / limitation |
|---|---|---|---|---|
| A | Reference | | | |
| B | Changed input | | | |
| A repeat | Reference | | | |
A conclusion is supported only when it cites the recorded values or observed states and explains them with the experiment theory.
Runnable Python implementation
Public teaching inputs only; not production-hardened. Python standard library is sufficient.
Inspect code, local variables, stack and output. Import a newly generated trace after editing the local program. No arbitrary Python executes in the browser.
How does addition introduce nonlinearity? Why is subtraction used in inverse processing? Compare SIMON and SPECK without inferring hardware performance from browser timing.
Explain the baseline trial, one negative control and the distinction between simulation and practical measurement.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research