Skip to content

Commit

Permalink
Consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mfukar committed Oct 6, 2016
1 parent 6a5582a commit a2566a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lfsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @author Michael Foukarakis
# @version 1.0
# @date Created: Thu Feb 03, 2011 08:19 GTB Standard Time
# Last Update: Wed Aug 28, 2013 10:22 BST
# Last Update: Thu Oct 06, 2016 14:40 CEST
#------------------------------------------------------------------------
# Description: Implementation of a Galois LFSR
# The bitstream is provided by the generator function
Expand Down Expand Up @@ -53,7 +53,7 @@ def bm(seq):
A generator is returned that yields the current LFSR at
each call. At the k-th call the yielded LFSR is guaranteed
to generate the first k bits of S.
to generate the first k bits of SEQ.
Input :
Output: A list of coefficients [c0, c1,..., c{m-1}]
Expand All @@ -66,31 +66,32 @@ def bm(seq):
The generating function G(x) = s_0 + s_1 * x^1 + s_2 * x^2 + ...
of a LFSR is rational and (when written in lowest terms) the
denominator f(x) is called the characteristic polynomial of the
LFSR. Here we have f(x) = c0 * x^m + c1 * x^{m-1} +...+ c{m-1} * x + 1."""
LFSR. Here we have f(x) = c0 * x^m + c1 * x^{m-1} +...+ c{m-1} * x + 1.
"""
# Allow for an input string along with a list or tuple
if type(S)==type("string"):
S = map(int,tuple(S))
if type(seq) == type('string'):
seq = map(int, tuple(seq))

m = 0

# N is the index of the current element of the sequence S under consideration
# N is the index of the current element of the sequence SEQ under consideration
# f is the characteristic polynomial of the current LFSR
N,f = 0,One

# N0 and f0 are the values of N and f when m was last changed
# N0 starts out as -1
N0,f0 = -1,One

n = len(S)
n = len(seq)
while N < n:
# Does the current LFSR compute the next entry in the
# sequence correctly? If not we need to update the LFSR
if S[N] != f.dot(S[:N]):
if seq[N] != f.dot(seq[:N]):
# If N is small enough we can get away with just
# updating the coefficients in the LFSR. Note that
# the 'X' occuring below is a global variable and
# is the indeterminant in the polynomials defined
# by the class 'Poly'. That is, X=Poly([1,0])
# by the class 'Polynomial'. That is, X=Polynomial([1,0])
if 2*m>N:
f = f + f0 * X**(N-N0)

Expand Down
4 changes: 2 additions & 2 deletions polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @author Michael Foukarakis
# @version 0.1
# @date Created: Sun Jul 10, 2011 03:03 PDT
# Last Update: Mon Jan 27, 2014 12:13 EET
# Last Update: Thu Oct 06, 2016 14:39 CEST
#------------------------------------------------------------------------
# Description: A class representing polynomials over GF(2).
# The coefficients are stored in a list.
Expand All @@ -28,7 +28,7 @@ def __add__(self, other):
new.pop(0)
except IndexError:
new = []
return Poly(new)
return Polynomial(new)

def dot(self,S):
""" This returns the sum of ck*S{N-k} where N+1 = len(S),
Expand Down

0 comments on commit a2566a4

Please sign in to comment.