API: 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,

Methods

Clocking (running LFSR):

Clocking (running LFSR)

Method

Discription

next()

Executing/running one cycle

runKCycle(k)

Executing/running k cycles

runFullPeriod()

Executing/running a full period of cylces

Setters :

Setting parameters

Method

Discription

reset()`

Reset to initial settings

set_fpoly(fpoly)

Change/set fpoly

set_conf(conf)

Change/set configuration

set_state(state)

Change/set state

set_seq_bit_index(bit_index)

Change/set seq_bit_index

Getters:

Fetching Attributes

Method

Discription

getFullPeriod()

Get sequence of a period

get_fPoly()

Get feedback polynomial

get_initState()

Get initial state

get_currentState()

Get current state

getState()

Get current state as string

get_outputSeq()

Get output sequence

getSeq()

Get output sequence as string

get_period()

Get period

get_expectedPeriod()

Get expected period

get_count()

Get counter

Testing LFSR Properties:

Testing Properties of LFSR

Method

Discription

test_properties()

Test all the properties for a valid LFSR

balance_property(p)

Test Balance property for a given sequence p

runlength_property(p)

Test Runlength property for a given sequence p

autocorr_property(p)

Test Autocorrelation property for a given sequence p

test_p(p)

Test three properties for a given sequence p

Displaying/printing:

Displaying/printing

Method

Discription

info()

Display all the attribuates of LFSR

print(L [LFSR Object] )

Display all the attribuates of LFSR (where L = LFSR())

repr(L [LFSR Object] )

Display all the input parameters of LFSR (where L = LFSR())

info()

Display all the attribuates of LFSR

Viz()

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

Deprecated methods for future version

Method

Discription

runFullCycle()

Changed to runFullPeriod(), full cycle is misnomer

set()

Changed to set_fpoly and set_state

changeFpoly(newfpoly)

Changed to set_fpoly

change_conf(conf)

Changed to set_conf

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