aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/mceliece/example_code
diff options
context:
space:
mode:
authorAndreas Müller <andreas.mueller@ost.ch>2021-09-01 11:40:47 +0200
committerGitHub <noreply@github.com>2021-09-01 11:40:47 +0200
commitcb9da449c0557bdfa7d67f3fd137bb1269096fd0 (patch)
treea0bdded0904566690b9a5cd0621ffa3883a1458a /buch/papers/mceliece/example_code
parenttypo (diff)
parenttypos & co (diff)
downloadSeminarMatrizen-cb9da449c0557bdfa7d67f3fd137bb1269096fd0.tar.gz
SeminarMatrizen-cb9da449c0557bdfa7d67f3fd137bb1269096fd0.zip
Merge pull request #95 from rfritsche/mceliece
Mceliece
Diffstat (limited to 'buch/papers/mceliece/example_code')
-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
+