A linear-feedback shift register of length has binary state and update
Its output obeys over . Since the state space is finite, its trajectory consists of a transient of length followed by a cycle of length , and the output satisfies for .
If the trajectory never reaches zero, all its distinct transient and cyclic states are nonzero; hence . If it reaches zero, let be its first zero-state time. The vectors are linearly independent: in a dependence, apply where is the smallest index with a nonzero coefficient; every later term vanishes and the remaining term is . Therefore . The zero cycle has , and for . This proves the requested bound for all , and for every invertible register.
The unrestricted printed assertion has one exception: at , the zero-feedback register with initial state one outputs . It requires , so . The universally valid finite-state bound is . A register with feedback from its oldest bit is invertible, in which case a nonzero state never reaches zero and the sharper bound holds already with .
To recover an unknown register from a known plaintext/ciphertext keystream, the Berlekamp-Massey algorithm finds a shortest linear recurrence consistent with the observed bits. Use a connection polynomial , so the recurrence discrepancy at index is . Initialize . Process the bits in order. If , increment . If , save and replace
If , also replace by , set ; otherwise retain and increment . Arithmetic is binary, so every nonzero discrepancy equals one. The stored polynomial last failed at an earlier index with discrepancy ; its shifted contribution cancels the new failure without changing previous successful discrepancies.
Here is the minimum recurrence length after a new discrepancy argument behind the update, not just its name. Suppose a span- recurrence succeeds through index but fails at . If another polynomial of span succeeded through and , compute the convolution at in two ways. Applying first gives zero, since all indices used by lie at least at . Applying first gives its nonzero discrepancy at , since its earlier discrepancies used by vanish and . This contradiction proves . The shifted-polynomial update attains the larger of the existing minimum length and this new lower bound; induction therefore gives the shortest recurrence for every prefix. Once at least twice the true linear complexity has been observed, this recurrence determines the whole stream: the difference from a true degree- recurrent stream satisfies a recurrence of degree at most , and a prefix of that many zeros forces every later value to be zero. Without any bound on complexity, a finite observed prefix cannot exclude a longer register that diverges later; the breaking claim uses the finite-register hypothesis and adequate known data.
Finally each of the three input streams is eventually periodic. Let be the maximum of their transient lengths and a common multiple of their periods. Their joint triple, and hence the bit chosen by the specified rule, repeats after once . Therefore
This itself is a linear recurrence of length , so it constructs a linear-feedback shift register producing the selected stream from its first bits. No closure theorem is being assumed: eventual periodicity and this explicit recurrence prove the combined stream is also an LFSR stream, even though the combining rule is nonlinear in its three inputs.
A binary linear-feedback shift register of length keeps bits and produces a sequence satisfying a recurrence
After each output it shifts its stored bits and inserts the feedback bit. Its connection polynomial is . This convention reverses the usual characteristic polynomial .
The Berlekamp-Massey algorithm recovers the shortest recurrence compatible with observed bits. Maintain the current , length , an earlier polynomial that last caused a length increase, and the offset since that increase. Initially . At position calculate the discrepancy . If , advance . If , save and replace by . If also , replace by , by and by one; otherwise increase . Over a general field the correction is , where is the saved nonzero discrepancy. The correction cancels the failed equation while retaining the previous successful ones; when it forces a length increase the smallest possible new length is .
Here, indexing the first bit by zero, the nonzero discrepancies occur at positions . The corresponding updates are
Every subsequent supplied discrepancy is zero. Thus
Equivalently the characteristic feedback polynomial is . No length-three recurrence works: positions force , but position six then has nonzero discrepancy. The recovered length is therefore minimal. Observing at least twice the true linear complexity ordinarily identifies the recurrence, after which a known consecutive block determines all future key bits. This is why a bare register is unsuitable as a cryptographic keystream generator; a finite prefix alone does not exclude a longer generator that later diverges.
A binary linear-feedback shift register stores bits, shifts them at each clock step, and inserts a fixed linear combination over of the stored bits. Its output obeys a recurrence . Write its connection polynomial as ; the corresponding monic feedback polynomial is .
The Berlekamp-Massey algorithm maintains the shortest recurrence fitting the observed prefix. Initialize , length , displacement , and previous nonzero discrepancy . At symbol , calculate . If , increase . If , save and replace by . If , replace by , by , by , and by ; otherwise only increase . In the binary field subtraction equals addition. The shifted previous discrepancy polynomial cancels the current discrepancy while preserving earlier equations. A failed recurrence of length at position requires a corrected length at least when this exceeds , explaining the length update. Thus the algorithm recovers the shortest compatible register; a known bound and at least output symbols suffice to identify its minimal recurrence.
For the printed twelve-bit prefix, the nonzero discrepancies occur at positions (indexing from zero). The successive updated pairs are
All remaining discrepancies vanish. Therefore
The first four observed bits are the fill. Length four is necessary: a length-three recurrence would need to hold already at and no such recurrence fits the prefix. Indeed the equations at force , , , a contradiction. Finite observations cannot rule out longer nonminimal registers.
True. A length- linear-feedback shift register has nonzero fills, and its first output bits recover its fill, so these fills give distinct output sequences. If lengths satisfy , the longer register has strictly more nonzero outputs. At least one is absent from the shorter register's output set; choosing any nonzero shorter fill then gives unequal outputs. This is the counting property of output sets of different-length linear-feedback registers.
False. Take and . The only nonzero length-one fill produces constant ones. Constant ones cannot satisfy the second linear recurrence relation, since in . Thus these linear-feedback shift registers have no identical outputs from nonzero fills.
A general feedback shift register of length over an alphabet stores , outputs , and shifts to for a fixed function . When the alphabet is a field , it is a linear-feedback shift register if is linear over , equivalently for fixed coefficients in . The binary case uses the finite field ; the examples and counterexamples below are binary.
For a genuinely nonlinear example take length three and . Its values at and are both zero, but its value at their sum is one, violating additivity. Thus this general register is not linear. It even has an invertible state update: from the old leading bit is , so the counterexample does not rely on allowing singular registers.
A binary linear-feedback shift register of length stores bits. At each clock it outputs one bit, shifts the state, and inserts a fixed linear combination over of the stored bits. Equivalently, its output obeys a recurrence
The Berlekamp-Massey algorithm processes the observed symbols from left to right. It maintains the shortest current connection polynomial , its degree , and a saved polynomial from the most recent degree increase. At step it computes the discrepancy
If , the current recurrence already predicts the new symbol. If , a shifted multiple of the saved polynomial is added to to cancel the discrepancy; when , the algorithm also replaces by and saves the old polynomial.
For the observed binary sequence, the nonzero-discrepancy updates are
All discrepancies through then vanish. Thus the shortest recurrence is
or, equivalently, . The connection polynomial is , and with the reciprocal convention the feedback polynomial is
A linear-feedback shift register is a linear map
For the stated matrix , a word lies in exactly when . If is its cyclic shift, periodicity gives
Thus is shift-invariant and is a binary cyclic code.
A general binary feedback shift register of length has state
and a feedback function . One update outputs the oldest bit, shifts the state, and inserts
The initial fill is . It is a linear-feedback shift register when
for fixed .
The Berlekamp-Massey algorithm reads an intercepted sequence from left to right while maintaining the shortest connection polynomial that reproduces the prefix. At each new symbol it computes the discrepancy between the observed bit and that predicted by the current recurrence. A zero discrepancy leaves the polynomial unchanged; a nonzero discrepancy adds a suitably shifted copy of the connection polynomial saved at the previous increase in linear complexity. After at least twice the unknown register length, it recovers the shortest recurrence, after which the entire keystream can be predicted.
Applying those discrepancy updates to
returns the connection polynomial
Equivalently, the sequence obeys
Indeed this predicts successively . No recurrence of length one or two fits the prefix, so its linear complexity is three.
Since generates , it cannot lie in a proper subfield, so its minimal polynomial over has degree . Write it as
The identity and characteristic two give
Multiplying by and applying the linear map yields
This is a binary linear recurrence of order at most , so is the output of a linear-feedback shift register of length at most .
A binary linear-feedback shift register of degree has a state
and recurrence
Its feedback polynomial is
There are states, and the zero state is fixed. A nonzero periodic orbit therefore visits at most the other states, proving the period bound for a linear-feedback shift register.
For a maximal orbit with , the all-one state cannot itself be fixed. From that state the incoming bit is in . If an odd number of the were one, the incoming bit would be one and the all-one state would be fixed. Hence an even number of the are one; including the leading coefficient, the feedback polynomial has an odd number of nonzero coefficients. This is the feedback-polynomial parity condition for maximal period.
The given prefix has seven consecutive zeros followed by a one. Any register of degree at most seven would therefore enter the all-zero state before producing the final one, which is impossible. Degree eight is attained by
with initial state . It produces the next bit and has feedback polynomial
Thus this is the minimal linear-feedback shift register for the prefix 100000001.