From 9ef53904ccf44f3c04bda08610cccb30fee47e50 Mon Sep 17 00:00:00 2001 From: Reto Fritsche Date: Tue, 31 Aug 2021 22:49:58 +0200 Subject: some corrections --- buch/papers/mceliece/example_code/mceliece_simple.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'buch/papers/mceliece/example_code') diff --git a/buch/papers/mceliece/example_code/mceliece_simple.py b/buch/papers/mceliece/example_code/mceliece_simple.py index bac3b42..c8d5e9d 100644 --- a/buch/papers/mceliece/example_code/mceliece_simple.py +++ b/buch/papers/mceliece/example_code/mceliece_simple.py @@ -187,14 +187,10 @@ def decode_linear_code(c, g, syndrome_table): q, r=divmod(Poly(c), g) q=np.r_[q.coef%2, np.zeros(len(c)-len(q)-len(g)+1)] r=np.r_[r.coef%2, np.zeros(len(g)-len(r))] - syndrome_index=np.sum([int(a*2**i) for i, a in enumerate(r)]) - while syndrome_index > 0: - c=c ^ syndrome_table[syndrome_index] - q, r=divmod(Poly(c), g) - q=np.r_[q.coef%2, np.zeros(len(c)-len(q)-len(g)+1)] - r=np.r_[r.coef%2, np.zeros(len(g)-len(r))] - syndrome_index=np.sum([int(a*2**i) for i, a in enumerate(r)]) - return np.array(q, dtype=int) + syndrome_index=np.sum([int(a*2**i) for i, a in enumerate(r)]) #binary to decimal + q_corr, r_corr=divmod(Poly(syndrome_table[syndrome_index]), g) + q_corr=np.r_[q_corr.coef%2, np.zeros(len(c)-len(q_corr)-len(g)+1)] + return q.astype(int) ^ q_corr.astype(int) def encode_linear_code(d, G): ''' @@ -324,4 +320,4 @@ if __name__ == '__main__': print(f'msg_rx: {msg_rx}') - \ No newline at end of file + -- cgit v1.2.1