lfsr-tools
Tools for pseudo-random number sequence generation and LFSR recovery.
Summary
This repository contains two basic classes:
- LFSR
- BerlekampMassey
LFSR
The LFSR class is a linear feedback shift register (LFSR) that creates a pseudo-random number (PN) sequence from a supplied generator polynomial. This generator polynomial specifies the LFSR architecture which determines what bit is fed back into the register. The LFSR-generated sequence should be obtained either by using an LFSR object as an iterator or using its next_state method.
Conventions
A polynomial is represented in big endian format. For example, the primitive polynomial $$x^4+x^3+1$$ is represented with its coefficients as $$[1 0 0 1 1].$$ In other words, the coefficient $c_0$ that multiplies $x^0$ is in the zeroth place of the array that specifies the generator polynomial. Similarly, the coefficient $c_N$ that multiplies $x^N$ is in the $N$th place of the array that specifies the generator polynomial.
The bit sequence that instantiates an LFSR object is specified in canonical order, so in the sequence $$[1 1 1 1 0 0 0 ... 0]$$ the bit that comes first in time at position zero is $1$ and the last bit of a sequence in position $M$ is, in this example, $0$. A seed is likewise explicitly specified on object instantiation or the implicit value of $[1 0 0 ...]$ is assumed.
BerlekampMassey
This class implements the seminal algorithm developed in 1967 by Elwyn Berlekamp and later recognized for its application to LFSRs by James Massey. An object of this class is instantiated on a bit sequence $s$ and returns a shortest-length polynomial that can generate it.
Intuition
Many examples and explanations exist illuminating the Berlekamp-Massey Algorithm and so only an intuition for how the algorithm works is provided here.
Suppose there is a black box that generates bits from a PN sequence which cannot be opened. Only the bits it generates can be observed. Assuming the black box generates its bits via a LFSR, the architecture of the lfsr can be recovered by designing a parallel LFSR which attempts to match the generated sequence $s$ which its own sequence $\hat{s}$. When the guess is wrong the LFSR architecture is updated so that the guess would have been correct and the process continues. The real magic of this algorithm is in putting forth an optimal architecture (specified by polynomial) update that keeps the LFSR length and computational burden to a minimum. An explanation of this magic is beyond the scope of this README.
LFSR Example
Suppose an LFSR specified with the primitive polynomial $x^4+x^3+1$ is desired. Such an LFSR is illustrated below where the $+$ operator is addition in GF(2) (i.e., exclusive-or).
┌──┐ ┌──┐ ┌──┐ ┌──┐ ┌──┐
┌─►│0 ├──►│1 ├──►│1 ├──►│1 ├─┐►│1 ├─┐
│ └──┘ └──┘ └──┘ └──┘ │ └──┘ │
│ │ │
│ ┌─▼─┐ │
└──────────────────────────┤ + │◄───┘
└───┘```
Instantiation of the LFSR and polynomial recovery is accomplished via
```python
from lfsr_tools import LFSR, BerlekampMassey
polynomial = [1 1 0 0 1]
lfsr = LFSR(polynomial)
sequence = [bit for bit in lfsr] #Sequence generation via iterator
bkm = BerlekampMassey(sequence)
bkm.estimate_polynomial()
print(f"The generator polynomial is: {[1 1 0 0 1]}")
Metadata
Release files for lfsr-tools 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lfsr-tools-0.0.1.tar.gz | 11.7 kB | Without provenance | Details for lfsr-tools-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lfsr_tools-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for lfsr_tools-0.0.1-py3-none-any.whl |
Total release size: 20.3 kB
Release files / lfsr-tools-0.0.1.tar.gz
| Download URL | lfsr-tools-0.0.1.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
822e3d574a7f1dd96b37e2f54f129ca6b648695060de09338422da781124dad3
|
|
BLAKE2b-256 checksum How to use checksums |
32b35cc1e7a3ddd69e9577fa309cc3f9151722b517ec3d83b231de1f22062ea6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Release files / lfsr_tools-0.0.1-py3-none-any.whl
| Download URL | lfsr_tools-0.0.1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04840ef3c97b04abc02b2cc99d4c8885732ebbb240373ac7a8a3a4f1df8e48c4
|
|
BLAKE2b-256 checksum How to use checksums |
405c0c288a072e12cbb7cea22d350c686bb3ab6847810fc4b356951ced68e7df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Security for lfsr-tools 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.