IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
CRYPTOGRAPHY ENGINEERING · CR29 · RANDOMNESS
IoT Security and Privacy
Randomness · statistical appearance and predictability
Distinguish entropy, statistical uniformity and unpredictability.
CR29 · Laboratory mentorAsk about the current operation and its intermediate values.
CR29 · Academic orientation
Scope and objectives
Scope of the experiment
Randomness tests measure selected statistical properties. Entropy quantifies uncertainty under a probability model; unpredictability requires an adversary-oriented model. Deterministic generators need secret, high-quality seed material.
The focus of this experiment is to calculate bit balance, runs and empirical entropy for finite sequences. Students then contrast statistical appearance with unpredictability, and explain why passing simple tests is insufficient for cryptographic randomness. 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
Calculate bit balance, runs and empirical entropy for finite sequences.
Contrast statistical appearance with unpredictability.
Explain why passing simple tests is insufficient for cryptographic randomness.
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 calculate bit balance, runs and empirical entropy for finite sequences, contrast statistical appearance with unpredictability, and explain why passing simple tests is insufficient for cryptographic randomness.
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 explain why passing simple tests is insufficient for cryptographic randomness. 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 LCG · recurrence, period and distribution.
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
CR29 · Randomness · statistical appearance and predictability
The empirical one-bit entropy H=−p log₂p−(1−p)log₂(1−p) uses only marginal frequencies. Runs count contiguous groups of equal bits. Adjacent-match fraction is the number of equal adjacent pairs divided by N−1. A balanced deterministic pattern can have H=1 but remain completely predictable.
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
The empirical one-bit entropy H=−p log₂p−(1−p)log₂(1−p) uses only marginal frequencies. Runs count contiguous groups of equal bits. Adjacent-match fraction is the number of equal adjacent pairs divided by N−1. A balanced deterministic pattern can have H=1 but remain completely predictable.
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.
Randomness metrics and unpredictability
1 · Principles and purpose
Randomness tests measure selected statistical properties. Entropy quantifies uncertainty under a probability model; unpredictability requires an adversary-oriented model. Deterministic generators need secret, high-quality seed material.
2 · Mathematical and algorithmic foundations
Empirical binary entropy H=−p log₂p−(1−p)log₂(1−p), with 0log0=0. A run is a maximal consecutive sequence of equal bits. Count runs and transitions separately.
3 · Worked teaching example
Sequence 01010101 has balanced bits and H=1 under the empirical estimate but is perfectly patterned. Statistical appearance does not establish cryptographic security.
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
Empirical binary entropy
p is the observed fraction of one bits, with 0 log 0 defined as zero. This measures marginal distribution, not sequence unpredictability or cryptographic strength.
\[H_2(p)=-p\log_2p-(1-p)\log_2(1-p)\]
For p=0.5 the result is one bit; for p=1 it is zero.
Concept animation · independent state notebook
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 2 · Input
Input
step
Input
bits
0101010101010101
Frequency and runs
step
Frequency and runs
ones
8
n
16
fraction
0.5
runs
16
entropy
1
adjacent_match
0
Teaching example only; inspect live calculations or real practical evidence separately.
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.
Distinguish entropy, statistical uniformity and unpredictability. Entropy estimate H=-Σp log₂p measures observed marginal distribution; runs count changes, adjacent-match detects simple dependence. Deterministic alternating bits can be balanced yet predictable.
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 bit sequence 001011011100, manually count zeros, ones and runs. Compute the fraction of ones and empirical binary entropy using the definition in Concepts. Explain why a short balanced sample is not proof of unpredictability.
Application and derivation — Empirical binary entropy H=−p log₂p−(1−p)log₂(1−p), with 0log0=0. A run is a maximal consecutive sequence of equal bits. Count runs and transitions separately. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Calculation
Calculation · Independent work
For bits 00011111, count runs, fraction ones and binary entropy estimate.
Calculation — 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 · CR29-01
For the separate teaching-test configuration bits: 0000111100001111, predict ones 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 · CR29-02
A teaching trace for Randomness · statistical appearance and predictability contains step: Frequency and runs; ones: 8; n: 16; fraction: 0.5; runs: 16. Explain the role of adjacent_match (recorded value 0) 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 · CR29-03
The first teaching trace contains step: Input; bits: 0101010101010101; the last contains step: Frequency and runs; ones: 8; n: 16; fraction: 0.5; runs: 16; entropy: 1; adjacent_match: 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 · CR29-04
Plan a comparison of bits: 0101010101010101 with bits: 0000111100001111. Record the dependent value runs, 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.
Compute frequencies and run count by hand for 0101010101010101, then verify using both steps. Predict the next bit assuming this deterministic pattern continues.
Export the trace and compare against the reference after recording your prediction.
Experimental inputs
Experimental reference · json
{"bits":"0101010101010101"}
Verified baseline reference (check after predicting)
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
N, ones fraction, runs, entropy and adjacent-match fraction.
Part D · Controlled experiment — Distinguish balance, runs and unpredictability
Use 0000111100001111 and 0000000000000000. Keep sequence length fixed. Compare the four metrics and explain why balanced sequences can have very different dependence.
Record all fixed settings and complete the trial table.
Measure N, ones fraction, runs, entropy and adjacent-match fraction. Compare against the baseline and explain the mechanism.
Trial
Input configuration
Prediction
Observed
Verification
1
{"bits":"0101010101010101"}
2
{"bits":"0000111100001111"}
3
{"bits":"0000000000000000"}
Use the table as a recording template; enter your own measured values in the field below or reproduce it in your report.
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 sequence to 0000111100001111 then 0000000000000000. First verified alternate: {"bits": "0000111100001111"}.
Keep length 16.
Measure frequency, runs, entropy and adjacent match.
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 CR29
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 CR29/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.
Recall before revealing. Review and mastery ratings remain on this device.
Browse all explanationsCan a perfectly balanced string be predictable?
Yes. Alternating bits are balanced but deterministic.
What is the dependent variable in this lab?
frequency, runs, entropy and adjacent match
What must remain controlled?
length 16
What input settings define the baseline for this experiment?
bits = 0101010101010101
What is the first intermediate state in the baseline?
step: Input; bits: 0101010101010101
What is a run?
A maximal contiguous sequence of equal bits.
Why can 0101 have H=1?
Half the symbols are ones, despite deterministic dependence.
What does adjacent-match measure?
The fraction of neighboring bits that match.
06 · Knowledge assessment
Formative check
Does empirical entropy H=1 imply cryptographic unpredictability?
Responses are for instructor review; no grading key is provided here.
Independent assessment
Create three 32-bit sequences with equal numbers of zeros and ones but different ordering. Compare runs and adjacent-match fractions, then state a counterexample to entropy implying unpredictability. 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.