Analyze polynomial roots, divisibility and irreducibility, then trace the state and period of a linear-feedback shift register.
The focus of this experiment is to represent binary polynomials and trace LFSR feedback taps. Students then calculate shift-register state, output bits and period, and explain why linear sequences alone are unsuitable cryptographic keystreams. 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
Represent binary polynomials and trace LFSR feedback taps.
Calculate shift-register state, output bits and period.
Explain why linear sequences alone are unsuitable cryptographic keystreams.
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 represent binary polynomials and trace LFSR feedback taps, calculate shift-register state, output bits and period, and explain why linear sequences alone are unsuitable cryptographic keystreams.
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 linear sequences alone are unsuitable cryptographic keystreams. 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 Modular arithmetic in Python — Reusable crypto functions.
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 Stream ciphers — Polynomials and LFSRs
Analyze polynomial roots, divisibility and irreducibility, then trace the state and period of a linear-feedback shift register.
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: Analyze polynomial roots, divisibility and irreducibility, then trace the state and period of a linear-feedback shift register.
Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
Polynomial roots and divisibility over reals — complete its numbered steps and record the requested evidence.
Polynomials over GF(2) — complete its numbered steps and record the requested evidence.
Three assigned LFSR traces — complete its numbered steps and record the requested evidence.
Reference check: The primitive 4-bit example yields period 15 for nonzero state; the zero state is absorbing. \(x^{2}\)+x+1 divides \(x^{4}\)+\(x^{2}\)+1.
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. Polynomial roots and divisibility over reals — 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.
Scientific concept map: Binary seed — Register bits; Feedback polynomial — XOR taps; Shift register — Clock transition; Output bit — Keystream; Period — State recurrence.
Polynomial arithmetic
Over the real numbers, a root a of P implies that X−a divides P. Over GF(2), coefficients are 0 or 1 and addition is XOR. Multiply polynomials by collecting coefficients modulo 2; division cancels the leading term until the remainder has smaller degree than the divisor.
Irreducibility and primitive feedback
A polynomial with a root and degree greater than one is reducible. A polynomial of degree four can have no linear root yet factor into quadratics. A primitive degree-n feedback polynomial produces a maximal-length nonzero LFSR cycle under the corresponding convention; irreducibility alone is insufficient.
Register evolution
A clock shifts the register and feeds back the XOR of selected taps. Record the complete state, output bit and first repeated state. Compare actual cycle length with 2^n−1 and identify transient states; the all-zero state is a fixed point for a linear recurrence.
Prerequisites: EC04 and earlier foundations as applicable.
Algorithm structure and data flow. Use the simulation to inspect the corresponding numerical transformations.
Engineering diagrams
Register feedback produces a deterministic bit sequence.
Scientific foundations and worked examples
Roots, divisibility and polynomial division
Over the reals, \(X^{2}\)−3X+2=(X−1)(X−2), whereas \(X^{2}\)−X−1 has roots (1±√5)/2. Over a field, P(a)=0 if and only if X−a divides P. Divisibility allows a constant quotient. Long division repeatedly cancels the leading term; in GF(2), subtraction equals addition, so the cancellation is XOR. (X+2)(X+3) becomes \(X^{2}\)+X in GF(2).
Irreducibility versus primitivity
A polynomial of degree at least two with a root in its coefficient field is reducible. The converse is false for degree four and above: \(X^{4}\)+\(X^{2}\)+1=(\(X^{2}\)+X+1)² over GF(2), though it has no binary root. For degrees two and three, absence of roots is sufficient. A primitive degree-n polynomial is irreducible and its root generates the nonzero elements of \(\mathrm{GF}(2^{n})\); irreducibility alone does not guarantee a maximal LFSR period.
Register timing and cycle measurement
For right-shifting registers [\(s_{2}\),\(s_{1}\),\(s_{0}\)] with feedback \(s_{1}\) XOR \(s_{0}\) (\(X^{3}\)+X+1), seed 100 evolves as 100→010→101→110→111→011→001→100. The period is 7. A primitive feedback polynomial gives \(2^{n}\)−1 for a nonzero seed under the matching convention. Record output bit, feedback bit and next register at each clock; stop on the first repeated state. If a transient leads into a cycle, period counts only the repeated cycle, not the transient. Linear feedback alone is predictable and is not a modern secure keystream generator.
Engineering principles · additional worked teaching example
An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability.
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
An LFSR shifts a bit register and inserts feedback formed by XOR of selected taps. For an n-bit nonzero-state maximal LFSR the upper period is 2^n−1. A linear recurrence is not a modern secure keystream.
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 · Register
Register
Register
1 0 1 1
Feedback
Register
1 0 1 1
Feedback
s0 XOR s3=0
Output
Register
1 0 1 1
Feedback
s0 XOR s3=0
Output
1; shift right
New register
Register
1 0 1 1
Feedback
s0 XOR s3=0
Output
1; shift right
New register
0 1 0 1
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 LFSR feedback?
XOR of selected register bits.
Why avoid all-zero seed?
A linear register remains zero.
Does irreducible imply primitive?
No; maximum period requires primitive feedback.
What is binary polynomial addition?
Coefficient-wise XOR.
What are the elements of GF(2)?
0 and 1.
What is addition in GF(2)?
XOR.
What does polynomial reduction mean?
Take the remainder after division by the modulus polynomial.
What is an irreducible polynomial?
A nonconstant polynomial with no nontrivial factors over the field.
Is every irreducible polynomial primitive?
No. Primitive is a stronger property.
Why is an all-zero LFSR seed unsuitable?
It is an absorbing state under linear feedback.
What is the maximum period of an n-stage binary LFSR?
2^n−1 for a primitive feedback polynomial and nonzero seed.
What does a tap define?
A register bit participating in feedback.
How do you measure period experimentally?
Clock until the entire initial register state repeats.
Why distinguish bit order from polynomial notation?
The chosen convention determines which taps and shifts implement the polynomial.
A 4-bit LFSR starts in all-zero state. What happens with XOR feedback?
The register remains zero. It cannot enter the nonzero maximal-length cycle.
A primitive degree-4 polynomial is used with a nonzero seed. What period is expected?
\(2^{4}\)−1=15, provided the implemented tap and shift convention matches that polynomial.
Why record the initial register and bit ordering?
Different conventions can produce different sequences from the same printed polynomial and seed.
Choose a workstation, edit the inputs, and observe recalculated results. Play or step through the actual calculation trace. Hash-search stations calculate successive candidates during playback. All inputs are fictional training data.
Where the browser requires Web Crypto, launch the local portal on localhost or use the HTTPS deployment. The classroom algorithms and keys are not intended for production use.
Independent theoretical exercises
Complete every question independently on paper or in the fields below before using the simulation or programming activities. Show formulas, intermediate steps, tables, proofs and units. Afterward verify your work using the simulator and Python, and explain discrepancies. Worked examples in Concepts do not replace your own derivation.
01 · Real polynomial roots
Find the real roots of \(X^{2}\)−3X+2 and \(X^{2}\)−X−1.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Polynomial divisibility
Let A=X+1, B=X−1, C=\(X^{2}\)+2X+1, D=\(X^{3}\)−\(X^{2}\)+X−1. Determine A|C, B|C, A|D and B|D by showing divisions.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Factorization
For L=\(X^{4}\)−17X²+16, verify roots 1 and −1, establish (\(X^{2}\)−1)|L, and complete the factorization.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
04 · GF(2) expansion
Expand (X+1)³, (X+1)⁴ and (X+1)⁵ over GF(2); factor \(X^{2}\)+1.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
05 · Irreducibility
Explain why a polynomial of degree >1 with a root is reducible. Find roots and factorizations of \(X^{2}\)+X and \(X^{2}\)+1. Test roots of C=\(X^{2}\)+X+1 and D=\(X^{4}\)+\(X^{2}\)+1, and establish C|D.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
06 · LFSR I
Draw the register for \(X^{3}\)+\(X^{2}\)+X. State the feedback convention, theoretical maximum period and irreducibility. Trace seed 100 through the first repeated state.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
07 · LFSR II
Draw the register for \(X^{4}\)+\(X^{2}\)+1, test irreducibility and trace seeds 1000 and 0110 separately. Compare actual and maximum periods.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
08 · LFSR III
Draw the register for \(X^{4}\)+\(X^{3}\)+1. Trace seed 1000, measure period and explain what the period establishes about this polynomial.
Engineering method — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
09 · Trace
Trace · Independent work
For recurrence (a,b,c)→(b,c,a XOR c), start (1,1,0), list three next states and emitted oldest bits.
Trace — An LFSR updates a finite binary state by XOR feedback and shifting. For a stated three-bit recurrence (a,b,c)→(b,c,a XOR c), state (1,0,0) becomes (0,0,1), then (0,1,1). All-zero stays zero. A maximal period does not imply unpredictability. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Responses are saved locally when browser storage is available. Export your work for submission. No automatic grading or remote upload occurs.
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 · EC05-01
Use state (1,0,1,1), output last bit, insert s0 XOR s3 at left. Calculate one step.
Intermediate · Calculate or trace
Independent theoretical exercise · EC05-02
Continue one further step using the same rule.
Intermediate · Interpret the result
Independent theoretical exercise · EC05-03
For a 5-bit LFSR, what is the longest possible nonzero-state period?
Advanced · Analyze a condition
Independent theoretical exercise · EC05-04
What happens to all-zero initial state under XOR feedback?
Advanced · Diagnose or compare
Independent theoretical exercise · EC05-05
Encrypt bits 101101 with stream 110010, then show recovery.
Challenging · Engineering verification
Independent theoretical exercise · EC05-06
Why does identical keystream for two messages reveal a relation?
Activity sequence
Follow the setup commands, then each named activity. The detailed instructions, given values and recording fields appear below.
Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
Compare observations with the reference checks and submit the required evidence.
Analytical preparation — before Python
Complete this written or hand-calculation activity first, then compare it with the simulator and executable implementation.
Factor the two real polynomials; prove the degree-four counterexample over GF(2). Draw the three assigned feedback registers and trace their periods by hand before running the simulation.
Evidence: show the derivation, intermediate values and independent checks; explain any mismatch with the practical result.
Practical laboratory manual
Scientific experimental protocol
Research question: How do feedback taps and polynomial arithmetic determine LFSR cycles?
Independent variables
Polynomial coefficients, divisor, initial register, tap set
Dependent observations
Remainder, period, transient, output bits
Controls
Fix register length and nonzero initial state when comparing taps; test all-zero state separately.
Validation and evidence
Before running a trial, predict its output. Use the baseline conditions below to check your method, then vary one independent variable. Save calculated outputs or the actual Python trace. Keep browser results and local Python execution distinct.
Trial
Controlled configuration
Reference check
Student observation (editable)
GF(2) division
10101 ÷ 111
Quotient 111, remainder 0
Enter observation
Primitive feedback
1000; taps 0,3 under portal convention
15 nonzero states before repeat
Enter observation
Zero control
0000; same taps
Fixed zero state, period 1
Enter observation
Analysis: Report the register bit ordering and feedback convention. Distinguish observed cycle length from mathematical proof of primitivity.
Analyze polynomial roots, divisibility and irreducibility, then trace the state and period of a linear-feedback shift register.
Equipment and execution
Browser-based simulator, Python 3, notebook or local evidence folder. Use WSL Setup only if you need a Linux runtime.
2. Follow these commands in sequence (Linux/WSL). For browser-only activities, open Simulation first; the code activities are independent.
BASH · Command
cd code
python lab05.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
Polynomial roots and divisibility over reals
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.
Find real roots of \(X^{2}\)−3X+2 and \(X^{2}\)−X−1. Check by substitution.
Set A=X+1, B=X−1, C=\(X^{2}\)+2X+1, D=\(X^{3}\)−\(X^{2}\)+X−1. Test all four A/B divides C/D combinations by factorization and long division.
For L=\(X^{4}\)−17X²+16, verify roots ±1, divide by \(X^{2}\)−1 and complete factorization.
Evidence to record
Roots, quotients, remainders, factorization.
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
Polynomials over GF(2)
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.
Test roots 0 and 1 for \(X^{2}\)+X and \(X^{2}\)+1, factor each. Then test \(X^{2}\)+X+1 and \(X^{4}\)+\(X^{2}\)+1.
Use polynomial long division to establish whether the first divides the second; explain why absence of linear roots does not imply irreducibility in degree 4.
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
Three assigned LFSR traces
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.
Draw the 3-bit register for P=\(X^{3}\)+\(X^{2}\)+X with initial 100; calculate theoretical maximum and trace until a repeat.
Draw Q=\(X^{4}\)+\(X^{2}\)+1 with initial 1000, then 0110. Compare cycles and transient states.
Draw R=\(X^{4}\)+\(X^{3}\)+1 with initial 1000; compare the cycle with maximum \(2^{4}\)−1. Match your taps to the simulator bit-order convention before comparing.
Run an all-zero state as a negative control and distinguish primitive from merely irreducible polynomials.
Evidence to record
For every initial state, register diagram, tap convention, ordered states, period and conclusion.
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.
Verification criteria
The primitive 4-bit example yields period 15 for nonzero state; the zero state is absorbing. \(x^{2}\)+x+1 divides \(x^{4}\)+\(x^{2}\)+1.
Deliverables
Submit polynomial computations, LFSR schematics, state/output traces, measured periods and explanation of primitive versus irreducible polynomials.
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: 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. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# EC05 · Stream ciphers — Polynomials and LFSRs
**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
Analyze polynomial roots, divisibility and irreducibility, then trace the state and period of a linear-feedback shift register.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
2. Polynomial roots and divisibility over reals — complete its numbered steps and record the requested evidence.
3. Polynomials over GF(2) — complete its numbered steps and record the requested evidence.
4. Three assigned LFSR traces — complete its numbered steps and record the requested evidence.
5. Compare observations with the reference checks and submit the required evidence.
**Evidence:** The primitive 4-bit example yields period 15 for nonzero state; the zero state is absorbing. \(x^{2}\)+x+1 divides \(x^{4}\)+\(x^{2}\)+1.
**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.
03Instructions · Markdown
## 2. Reference configuration and investigation
1. Complete the analytical preparation below before programming. Show the intermediate mathematical calculations.
2. Polynomial roots and divisibility over reals — complete its numbered steps and record the requested evidence.
3. Polynomials over GF(2) — complete its numbered steps and record the requested evidence.
4. Three assigned LFSR traces — complete its numbered steps and record the requested evidence.
5. 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. Algorithm implementation
Read each definition and relate it to the equations and scientific SVGs in Concepts.
05Instructions · Markdown
### Implementation cell 1
Inspect the definitions, then execute to make them available for the investigation.
06Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC05 | Code cell 01 | Stream ciphers — Polynomials and LFSRs
# Purpose: Implementation cell 1 Inspect the definitions, then execute to make them available for the investigation.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
"""Essential 05 — GF(2) polynomial arithmetic and LFSR state traces."""
# Define the reusable operation gf2 multiply; keep its logic separate from the trial.
def gf2_multiply(a,b):
out=0
while b:
if b&1: out^=a
a<<=1; b>>=1
return out
# Define the reusable operation gf2 divide; keep its logic separate from the trial.
def gf2_divide(a,b):
if a<0 or b<=0: raise ValueError('Nonnegative binary polynomials, nonzero divisor required')
q=0
while a and a.bit_length()>=b.bit_length():
k=a.bit_length()-b.bit_length(); q^=1<<k; a^=b<<k
return q,a
### Implementation cell 2
Inspect the definitions, then execute to make them available for the investigation.
08Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC05 | Code cell 02 | Stream ciphers — Polynomials and LFSRs
# Purpose: Implementation cell 2 Inspect the definitions, then execute to make them available for the investigation.
# 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 lfsr trace; keep its logic separate from the trial.
def lfsr_trace(state,taps):
if not 2<=len(state)<=10 or set(state)-{'0','1'} or not taps or len(set(taps))!=len(taps) or any(i<0 or i>=len(state) for i in taps):
raise ValueError('Invalid register or tap indices')
seen={}; trace=[]
while state not in seen:
seen[state]=len(trace); feedback=0
for i in taps: feedback^=int(state[i])
nxt=str(feedback)+state[:-1]; trace.append((state,feedback,state[-1],nxt)); state=nxt
return trace,len(trace)-seen[state],seen[state]
## 4. Execute reference controls
The program checks selected algorithm outcomes. Record the observed output. These checks do not replace the independent calculation assignment.
10Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC05 | Code cell 03 | Stream ciphers — Polynomials and LFSRs
# Purpose: 4. Execute reference controls The program checks selected algorithm outcomes. Record the observed output. These checks do not replace the independent calculation assignment.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert gf2_divide(21, 7) == (7, 0)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert gf2_multiply(7, 7) == 21
# Repeat the same operation for each configured input so observations are comparable.
for state, taps in [('100', [0, 1]), ('1000', [1, 3]), ('0110', [1, 3]), ('1000', [0, 3]), ('0000', [0, 3])]:
trace, period, transient = lfsr_trace(state, taps)
print(state, taps, period, transient)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert lfsr_trace('1000', [0, 3])[1] == 15
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert lfsr_trace('0000', [0, 3])[1] == 1
## 5. Controlled variation
Predict the effect of the parameter changes below. Compare each actual result to your prediction.
12Python · executable cell
PYTHON · Code cell
# =====================================================================
# EC05 | Code cell 04 | Stream ciphers — Polynomials and LFSRs
# Purpose: 5. Controlled variation Predict the effect of the parameter changes below. Compare each actual result to your prediction.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Repeat the same operation for each configured input so observations are comparable.
for n in (0b1011,0b1111):
print(bin(n),"polynomial encoding")
## 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.)
14Instructions · 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. Polynomial roots and divisibility over reals — 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.
Python implementation
Download the complete practical toolkit and extract it to a new directory. Keep the code and challenges folders together.
Explore actual CPython execution traces from the included laboratory programs. Play, pause, step, inspect the current line, local variable values, function call stack, return values and output. Green variable cells changed relative to the preceding event. Line events show state before the highlighted line executes.
Run and visualize your own modified Python program
Download the Essential Cryptography Toolkit, extract it, and open a terminal in its code directory. Run the worked example or edit a copy. The trace generator executes your actual local Python file and creates an importable JSON record. Only run trusted code and use fictional keys and data.
Choose Import your trace in the visualizer and select my-trace.json. This works offline; the portal does not execute arbitrary Python on its server. The optional external Python Tutor link is suitable for standalone standard-library code, but external dependencies or local imports may not work.
For AES/DES exercises, install either supported cryptographic backend in an isolated Python environment as described in the Python code tab. Native library internals are not traced; the algorithm-specific browser workstations display the intermediate mathematics.
Submission: Submit polynomial computations, LFSR schematics, state/output traces, measured periods and explanation of primitive versus irreducible polynomials.
Export actual calculated observations from each workstation. Record your own predictions and conclusions, and distinguish browser calculations from local or physical measurements.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research