aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/mceliece/example_code
diff options
context:
space:
mode:
authorReto Fritsche <reto.fritsche@ost.ch>2021-08-31 22:49:58 +0200
committerReto Fritsche <reto.fritsche@ost.ch>2021-08-31 22:49:58 +0200
commit9ef53904ccf44f3c04bda08610cccb30fee47e50 (patch)
tree1d8ac758954490b2607ef26271cbc9a74f779085 /buch/papers/mceliece/example_code
parentcreated example, made some succested correction/improvements (diff)
downloadSeminarMatrizen-9ef53904ccf44f3c04bda08610cccb30fee47e50.tar.gz
SeminarMatrizen-9ef53904ccf44f3c04bda08610cccb30fee47e50.zip
some corrections
Diffstat (limited to '')
-rw-r--r--buch/papers/mceliece/example_code/mceliece_simple.py14
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
+