Skip to content

Commit

Permalink
Polynomial now returns a correct string representation of itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Foukarakis committed Aug 28, 2013
1 parent f7db900 commit e72e479
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 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: Tue Mar 26, 2013 12:41 GTB Standard Time
# Last Update: Wed Aug 28, 2013 10:22 BST
#------------------------------------------------------------------------
# Description: Implementation of a Galois LFSR
# The bitstream is provided by the generator function
Expand Down Expand Up @@ -47,7 +47,7 @@ def states(self, repeat=False):
One = Polynomial([1])

def bm(seq):
'''Implementation of the Berlekamp-Massey algorithm, the purpose
"""Implementation of the Berlekamp-Massey algorithm, the purpose
of which is to find a LFSR with the smallest possible length
that generates a given sequence.
Expand All @@ -66,7 +66,7 @@ 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))
Expand Down
9 changes: 4 additions & 5 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 24, 2011 14:54 GTB Standard Time
# Last Update: Wed Aug 28, 2013 10:23 BST
#------------------------------------------------------------------------
# Description: A class representing polynomials over GF(2).
# The coefficients are stored in a list.
Expand All @@ -14,9 +14,8 @@

class Polynomial(list):
def __str__(self):
L = ['x^{}'.format(k) for k in enumerate(self[::-1]) if x == 1]
L.reverse()
return '+'.join(L)
L = ['{}*x^{}'.format(e, i) for i,e in enumerate(self)]
return ' + '.join(L)

def __add__(self, other):
if len(self) < len(other):
Expand Down Expand Up @@ -57,5 +56,5 @@ def __pow__(self,ex):


def dot(x, y):
'''Returns the dot product of two lists.'''
"""Returns the dot product of two lists."""
return reduce(xor, [a&b for (a,b) in zip(x,y)], 0)

0 comments on commit e72e479

Please sign in to comment.