Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
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
Show more breadcrumbs
repos.quentin.fasler
math-1
Reed-Solomon
Commits
71d09cc2
Commit
71d09cc2
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
077fa6fa
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
-10
7 additions, 10 deletions
polynomial.py
with
7 additions
and
10 deletions
polynomial.py
+
7
−
10
View file @
71d09cc2
import
math
import
itertools
import
math
def
unicode_superscripts
(
number
):
...
...
@@ -27,7 +27,6 @@ class Polynomial:
Raises:
TypeError: The type of the parameter
"
value
"
is not a tuple.
"""
if
not
isinstance
(
value
,
tuple
):
raise
TypeError
(
'
The
"
value
"
parameter is not of type tuple.
'
)
self
.
value
=
value
...
...
@@ -61,7 +60,7 @@ class Polynomial:
b
=
list
(
other
.
value
)
c
=
[]
#
itertools pad 0 to the lowest list
.
#
Adds 0's to the list a if its length is less than that of b and vice versa
.
for
(
ai
,
bi
)
in
itertools
.
zip_longest
(
a
,
b
,
fillvalue
=
0
):
c
.
append
(
ai
+
bi
)
return
Polynomial
(
tuple
(
c
))
...
...
@@ -113,13 +112,13 @@ class Polynomial:
for
i
,
x
in
enumerate
(
reversed
(
self
.
value
)):
x
=
math
.
ceil
(
x
)
if
x
==
0
:
continue
if
i
!=
0
:
str_value
+=
"
+
"
if
x
>=
0
else
"
-
"
if
x
!=
1
or
i
==
len
(
self
.
value
)
-
1
:
str_value
+=
str
(
abs
(
x
))
if
len
(
self
.
value
)
-
i
-
1
>=
1
:
str_value
+=
"
x
"
if
len
(
self
.
value
)
-
i
-
1
>=
2
:
...
...
@@ -145,16 +144,15 @@ def get_bezout_coefficients(a, b):
while
True
:
r
.
append
(
r
[
i
-
2
]
%
r
[
i
-
1
])
# Continue until the rest is equal to 0
if
r
[
i
]
==
0
:
break
q
.
append
(
int
(
r
[
i
-
2
]
/
r
[
i
-
1
]))
x
.
append
(
x
[
i
-
2
]
-
q
[
i
]
*
x
[
i
-
1
])
y
.
append
(
y
[
i
-
2
]
-
q
[
i
]
*
y
[
i
-
1
])
i
+=
1
return
x
[
-
1
],
y
[
-
1
]
...
...
@@ -223,27 +221,26 @@ def reed_solomon(points, data_length, last_error_index, prime_number):
# Create the lagrange polynomial with the sublist of points
lagrange
=
compute_lagrange_polynomial
(
sub_points
,
prime_number
)
nb_valid_points
=
0
# Parse each points to verify if the polynomial is correct
for
p
in
points
:
x
=
p
[
0
]
# Pass the x value of each points through the lagrange polynomial
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
# Verify if we have enough valid points, so it must be equal or higher than m + n points
# // = euclid division
if
nb_valid_points
>=
data_length
+
(
len
(
points
)
-
data_length
)
//
2
:
# Decode the message
output
=
""
for
i
in
range
(
data_length
):
output
+=
chr
(
lagrange
.
evaluate_x
(
i
)
%
prime_number
)
return
output
return
None
...
...
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