API References¶
LFSR Class¶
Linear Feedback Shift Register
Python implementation of LFSR
class pylfsr.LFSR(fpoly=[5, 2], initstate='ones',
conf='fibonacci', seq_bit_index=-1,
verbose=False, counter_start_zero=True)
Parameters:¶
- fpolylist, optional (default=[5,2]):
Feedback polynomial, it has to be primitive polynomial of GF(2) field, for valid output of LFSR.
Example: for 5-bit LFSR, fpoly=[5,2], [5,3], [5,4,3,2], etc for M-bit LFSR fpoly = [M,…]
To get the list of feedback polynomials check method ‘get_fpolyList’ or check Refeferece: Ref: List of some primitive polynomial over GF(2)can be found at
- initstatebinary np.array (row vector) or str =’ones’ or ‘random’, optional (default = ‘ones’)):
Initial state vector of LFSR. initstate can not be all zeros.
- default (initstate=’ones’)
Initial state is intialized with ones and length of register is equal to degree of feedback polynomial
- if state=’rand’ or ‘random’
Initial state is intialized with random binary sequence of length equal to degree of feedback polynomial
- if passed as list or numpy array
example initstate = [1,1,0,0,1]
Theoretically the length initial state vector should be equal to order of polynomial (M), however, it can easily be bigger than that which is why all the validation of state vector and fpoly allows bigger length of state vector, however small state vector will raise an error.
- counter_start_zero: bool (default = True), whether to start counter with 0 or 1:
If True, initial outbit is set to -1, so is feedbackbit, until first .next() clock is excecuted.
This initial output is not stacked in seq. The output sequence should be same, in anycase, for example if you need run 10 cycles, using runKCycle(10) methed.
- verboseboolean, optional (default=False):
If True, state of LFSR will be printed at every cycle(iteration)
- conf: str {‘fibonacci’, ‘galois’}, default conf=’fibonacci’:
: configuration mode of LFSR, either fabonacci or galoisi. : Example of 16-bit LFSR:
Fibonacci: https://en.wikipedia.org/wiki/Linear-feedback_shift_register#/media/File:LFSR-F16.svg Galois: https://en.wikipedia.org/wiki/Linear-feedback_shift_register#/media/File:LFSR-G16.svg
- seq_bit_index: int, index of shift register for output sequence:
Default=-1, which means the last register.
: seq_bit_index can varies from -M to M-1,for M-bit LFSR. For example 5-bit LFSR, seq_bit_index=-5,-4,-3,-2,-1, 0, 1, 2, 3, 4 : seq_bit_index=-1, means output sequence is taken out from last Register, -2, second last,
List of Methods¶
Methods¶
Clocking (running LFSR):¶
Method |
Discription |
---|---|
|
Executing/running one cycle |
|
Executing/running k cycles |
|
Executing/running a full period of cylces |
Setters :¶
Method |
Discription |
---|---|
|
Reset to initial settings |
|
Change/set fpoly |
|
Change/set configuration |
|
Change/set state |
|
Change/set seq_bit_index |
Getters:¶
Method |
Discription |
---|---|
|
Get sequence of a period |
|
Get feedback polynomial |
|
Get initial state |
|
Get current state |
|
Get current state as string |
|
Get output sequence |
|
Get output sequence as string |
|
Get period |
|
Get expected period |
|
Get counter |
Testing LFSR Properties:¶
Method |
Discription |
---|---|
|
Test all the properties for a valid LFSR |
|
Test Balance property for a given sequence p |
|
Test Runlength property for a given sequence p |
|
Test Autocorrelation property for a given sequence p |
|
Test three properties for a given sequence p |
Displaying/printing:¶
Method |
Discription |
---|---|
|
Display all the attribuates of LFSR |
|
Display all the attribuates of LFSR (where |
|
Display all the input parameters of LFSR (where |
|
Display all the attribuates of LFSR |
|
Display LFSR as a figure with a current state of LSFR with feedback polynomials and given configuration |
Deprecated/replaced methods :¶
These methods will be deprecated in future version 1.0.7
Method |
Discription |
---|---|
|
Changed to |
|
Changed to |
|
Changed to |
|
Changed to |
Attributes¶
- countint
Count the cycle, starts with 0 if counter_start_zero True, else starts with 1
- seqnp.array shape =(count,)
Output sequence stored in seq since first cycle if -1, no cycle has been excecuted, count=0 when counter_start_zero is True else last bit of initial state
- outbitbinary bit
Current output bit, Last bit of current state If -1, no cycle has been excecuted, count =0, when counter_start_zero is True
- feedbackbitbinary bit
If -1, no cycle has been excecuted, count =0, when counter_start_zero is True
- Mint
Length of LFSR, M-bit LFSR
- expectedPeriodint (also saved as T)
Expected period of sequence. If feedback polynomial is primitive and irreducible (as per reference) period will be 2^M -1
- Tint (also saved as expectedPeriod)
Expected period of sequence If feedback polynomial is primitive and irreducible (as per reference) period will be 2^M -1
- feedpolystr
feedback polynomial