Documentation
¶
Overview ¶
Package lfsr provides stream-cipher / LFSR analysis primitives relevant to RF scramblers and keystream study: Berlekamp–Massey recovery of the shortest LFSR that produces an observed bit sequence, Fibonacci-LFSR generation, and known-plaintext keystream extraction.
All bit sequences are represented as []byte holding 0/1 values (one bit per element), which keeps the algorithms readable; BitsFromBytes/ BytesToBits convert to and from packed bytes (MSB-first).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitsFromBytes ¶
BitsFromBytes expands packed bytes into a 0/1 bit slice, MSB first.
func BitsToBytes ¶
BitsToBytes packs a 0/1 bit slice into bytes, MSB first. Trailing bits that do not fill a byte are left-aligned (zero-padded on the right).
func Generate ¶
Generate produces n output bits from a Fibonacci LFSR with the given 1-based tap positions and an initial state seed (seed[0] is the first bit shifted out). The register length is the max tap. Output bit = the bit leaving the register; feedback = XOR of the tapped stages. seed length must be at least the register length.
Types ¶
type Result ¶
Result is the outcome of Berlekamp–Massey: the linear complexity L (the length of the shortest LFSR) and the connection polynomial C(x) = 1 + c1·x + ... + cL·x^L as coefficients [1, c1, ..., cL] over GF(2).
func BerlekampMassey ¶
BerlekampMassey returns the shortest LFSR (over GF(2)) consistent with the bit sequence s (each element 0 or 1). The linear complexity is a strong fingerprint: a short LFSR means a simple scrambler; complexity ≈ len(s)/2 means no short linear generator (the sequence looks random to a linear model).