Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Proper sanity checks for output of decode_to_* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lucas committed Feb 24, 2016
1 parent 57dbfbf commit 7953d60
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/sage/coding/grs.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,15 @@ def decode_to_message(self, r):
return self.connected_encoder().unencode_nocheck(r)
col_mults = C.column_multipliers()

r = [r[i]/col_mults[i] for i in range(0, C.length())]
r_list = copy(r)
r_list = [r[i]/col_mults[i] for i in range(0, C.length())]

t = (C.minimum_distance()-1) // 2
l0 = n-1-t
l1 = n-1-t-(k-1)
S = matrix(C.base_field(), n, l0+l1+2, lambda i,j :
(C.evaluation_points()[i])**j if j<(l0+1)
else r[i]*(C.evaluation_points()[i])**(j-(l0+1)))
else r_list[i]*(C.evaluation_points()[i])**(j-(l0+1)))
S = S.right_kernel()
S = S.basis_matrix().row(0)
R = C.base_field()['x']
Expand All @@ -1005,9 +1006,10 @@ def decode_to_message(self, r):
if not Q1.divides(Q0):
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")
f = (-Q0)//Q1

if f not in R:
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")
if (R(r.list()) - f).degree() < self.decoding_radius():
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")

return f

Expand Down Expand Up @@ -1283,7 +1285,8 @@ def decode_to_message(self, r):

if h not in PolRing:
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")

if (PolRing(r.list()) - h).degree() < self.decoding_radius():
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")
return h

def decoding_radius(self):
Expand Down Expand Up @@ -1724,7 +1727,7 @@ def _syndrome(self, r):

def _forney_formula(self, error_evaluator, error_locator):
r"""
Returns the error vector computed through Forney's formula as a list.
Returns the error vector computed through Forney's formula.
INPUT:
Expand All @@ -1743,7 +1746,7 @@ def _forney_formula(self, error_evaluator, error_locator):
sage: R.<x> = F[]
sage: evaluator, locator = R(10), R([10, 10])
sage: D._forney_formula(evaluator, locator)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
"""
C = self.code()
alphas = C.evaluation_points()
Expand All @@ -1760,7 +1763,7 @@ def _forney_formula(self, error_evaluator, error_locator):
else:
e.append(zero)

return e
return vector(F, e)

def decode_to_code(self, r):
r"""
Expand Down Expand Up @@ -1827,11 +1830,10 @@ def decode_to_code(self, r):
(EEP, ELP) = self._partial_xgcd(a, S, PolRing)

e = self._forney_formula(EEP, ELP)
dec = []
for i in range(len(r)):
dec.append(r[i] - e[i])
dec = vector(F, dec)
if not dec in C:
dec = r - e
if dec not in C:
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")
if (r - dec).hamming_weight() > self.decoding_radius():
raise DecodingError("Decoding failed because the number of errors exceeded the decoding radius")
return dec

Expand Down

0 comments on commit 7953d60

Please sign in to comment.