diff options
Diffstat (limited to '')
-rw-r--r-- | buch/papers/mceliece/example_code/mceliece_simple.py | 14 |
1 files changed, 5 insertions, 9 deletions
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 + |