PyLFSR: Linear Feedback Shift Register

Verson: 1.0.7

Github Page | Discussion Forum | Github PyPI - Downloads PyPI - Hist-of-code CircleCI Documentation Status PyPI PyPI Format PyPI Implementation PyPI Python Version GitHub Repo stars GitHub forks

Linear Feedback Shift Register - Documentation.

PyLFSR is an open source Python library to create Pseudo-Random Generator based on Linear Feedback Shift Registe. It is easy to use and create Pseudo-Random Generator, with custom configurations, such as A5/1, its enhacement, Geffe Genrator and many more. A generated sequence can be tested across different properties.

A simple example of generating 5-bit LFSR with feedback polynomial of p(x) = x5+ x3+1

import numpy as np
from pylfsr import LFSR

state = [0,0,0,1,0]
fpoly = [5,3]
L = LFSR(fpoly=fpoly,initstate =state)

# Generate K-bits
seq_k  = L.runKCycle(k)

print('10 bits')

# Generate bits of one full period.
# Expected period of LFSR = 2^M-1, for M-bit LFSR).
seq_full  = L.runFullPeriod()

print('Full period of LFSR = 31-cycles')

10 bits

Full period of LFSR = 31-cycles

NOTE on visualization: Feedback bit shown in figure (while visualizing), is feedback computed from previous state, NOT from current state. Check visualization section for more details

Galois LFSR

A simple example for Galois LFSR is:
import numpy as np
from pylfsr import LFSR

state = [1,1,0,1,1]
fpoly = [5,3]
L = LFSR(fpoly=fpoly,initstate =state,conf='galois')



If any doubt, confusion or feedback please contact me

  • n.bajaj[AT]

  • n.bajaj[AT]

  • nikkeshbajaj[AT]gmail[dot?]

Nikesh Bajaj:

Queen Mary University of London

Imperial Collage London

Github Page | Discussion Forum | Github