Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_122 - Travail Pratique 001 - Code de Reed-Solomon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_122 - Travail Pratique 001 - Code de Reed-Solomon
Commits
f404be30
Commit
f404be30
authored
3 years ago
by
quentin.fasler
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of
ssh://ssh.hesge.ch:10572/florian.burgener/math-tp-001
parents
4e2b959e
eea1ca3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polynomial.py
+7
-17
7 additions, 17 deletions
polynomial.py
with
7 additions
and
17 deletions
polynomial.py
+
7
−
17
View file @
f404be30
...
...
@@ -32,7 +32,7 @@ class Polynomial:
raise
TypeError
(
'
The
"
value
"
parameter is not of type tuple.
'
)
self
.
value
=
value
def
pass_x_throughout
(
self
,
x
):
def
evaluate_x
(
self
,
x
):
"""
Evaluate the polynomial by passing x
Args:
...
...
@@ -60,20 +60,10 @@ class Polynomial:
a
=
list
(
self
.
value
)
b
=
list
(
other
.
value
)
a_count
=
len
(
a
)
b_count
=
len
(
b
)
if
a_count
>
b_count
:
diff
=
a_count
-
b_count
for
x
in
range
(
diff
):
b
.
append
(
0
)
else
:
diff
=
b_count
-
a_count
for
x
in
range
(
diff
):
a
.
append
(
0
)
c
=
[
0
]
*
len
(
a
)
for
x
in
range
(
len
(
a
)):
c
[
x
]
=
a
[
x
]
+
b
[
x
]
c
=
[]
# itertools pad 0 to the lowest list
for
(
a
,
b
)
in
itertools
.
zip_longest
(
a
,
b
,
fillvalue
=
0
):
c
.
append
(
a
+
b
)
return
Polynomial
(
tuple
(
c
))
...
...
@@ -239,7 +229,7 @@ def reed_solomon(points, data_length, last_error_index, prime_number):
for
p
in
points
:
x
=
p
[
0
]
# Pass the x value of each points through the lagrange polynomial
y
=
lagrange
.
pass_x_throughout
(
x
)
%
prime_number
y
=
lagrange
.
evaluate_x
(
x
)
%
prime_number
# If the result is the same that the y value, then the point is correct
if
y
==
p
[
1
]:
nb_valid_points
+=
1
...
...
@@ -249,7 +239,7 @@ def reed_solomon(points, data_length, last_error_index, prime_number):
# Decode the message
output
=
""
for
i
in
range
(
data_length
):
output
+=
chr
(
lagrange
.
pass_x_throughout
(
i
)
%
prime_number
)
output
+=
chr
(
lagrange
.
evaluate_x
(
i
)
%
prime_number
)
return
output
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment