LFSR
Implements a binary Galois Linear Feedback Shift Register with arbitrary size n
.
A LFSR is a shift register whose input bit is a linear function of its previous state.
The bit positions that affect the next state are called the taps.
A LFSR with well chosen taps will produce a maximum cycle, meaning that a register
with size n
will produce a sequence of length 2n-1 without repetitions.
The LFSR can be initialized by providing a starting state and the desired size of the register. In this case, a table of default taps that generate the maximum cycle is used.
Alternatively, the LFSR can be initialized with the starting state and a list of taps. Note however that not all combinations of taps will produce the maximum cycle.
Summary
Functions
Initializes and returns a new LFSR. The LFSR is represented using a Struct
Takes the LFSR and returns the LFSR in the next state
Convenience function to fetch the state of a LFSR
Functions
Initializes and returns a new LFSR. The LFSR is represented using a Struct.
The first argument is the starting state and must be a number greater than 0 and
less than 2n, where n
is the size of the register.
The second argument is either the size in bits of the register or a list of taps.
Examples
iex> LFSR.new(1, 8)
%LFSR{mask: 184, state: 1}
iex> LFSR.new(1, [8, 6, 5, 4])
%LFSR{mask: 184, state: 1}
Takes the LFSR and returns the LFSR in the next state.
Examples
iex> LFSR.new(1, 8)
%LFSR{mask: 184, state: 1}
iex> LFSR.new(1, 8) |> LFSR.next
%LFSR{mask: 184, state: 184}