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
2330805e
Commit
2330805e
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Prepare message data
parent
73f7a3d3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polynomial.py
+35
-53
35 additions, 53 deletions
polynomial.py
with
35 additions
and
53 deletions
polynomial.py
+
35
−
53
View file @
2330805e
...
...
@@ -6,24 +6,23 @@ from typing import Tuple
def
unicode_superscripts
(
value
):
exponent_dict
=
{
"
0
"
:
"
⁰
"
,
"
1
"
:
"
¹
"
,
"
2
"
:
"
²
"
,
"
3
"
:
"
³
"
,
"
4
"
:
"
⁴
"
,
"
5
"
:
"
⁵
"
,
"
6
"
:
"
⁶
"
,
"
7
"
:
"
⁷
"
,
"
8
"
:
"
⁸
"
,
"
9
"
:
"
⁹
"
}
exponent_dict
=
{
"
0
"
:
"
⁰
"
,
"
1
"
:
"
¹
"
,
"
2
"
:
"
²
"
,
"
3
"
:
"
³
"
,
"
4
"
:
"
⁴
"
,
"
5
"
:
"
⁵
"
,
"
6
"
:
"
⁶
"
,
"
7
"
:
"
⁷
"
,
"
8
"
:
"
⁸
"
,
"
9
"
:
"
⁹
"
}
return
(
"
⁻
"
if
value
<
0
else
""
)
+
""
.
join
(
exponent_dict
[
x
]
for
x
in
str
(
abs
(
value
)))
class
Polynomial
:
def
__init__
(
self
,
value
=
()):
if
not
isinstance
(
value
,
tuple
):
raise
TypeError
(
"
The
\
"
value
\
"
parameter is not of type tuple.
"
)
raise
TypeError
(
'
The
"
value
"
parameter is not of type tuple.
'
)
self
.
value
=
value
def
pass_x_throughout
(
self
,
x
):
a
=
list
(
self
.
value
)
sum
=
(
a
[
len
(
a
)
-
1
]
*
x
)
+
a
[
len
(
a
)
-
2
]
for
i
in
reversed
(
range
(
len
(
a
)
-
2
)):
sum
=
sum
*
x
+
a
[
i
]
sum
=
(
a
[
len
(
a
)
-
1
]
*
x
)
+
a
[
len
(
a
)
-
2
]
for
i
in
reversed
(
range
(
len
(
a
)
-
2
)):
sum
=
sum
*
x
+
a
[
i
]
return
sum
def
__add__
(
self
,
other
):
a
=
list
(
self
.
value
)
b
=
list
(
other
.
value
)
...
...
@@ -31,17 +30,17 @@ class Polynomial:
a_count
=
len
(
a
)
b_count
=
len
(
b
)
if
a_count
>
b_count
:
diff
=
a_count
-
b_count
diff
=
a_count
-
b_count
for
x
in
range
(
diff
):
b
.
append
(
0
)
else
:
diff
=
b_count
-
a_count
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
[
x
]
=
a
[
x
]
+
b
[
x
]
return
Polynomial
(
tuple
(
c
))
...
...
@@ -50,12 +49,12 @@ class Polynomial:
b
=
list
(
other
.
value
)
a_count
=
len
(
a
)
b_count
=
len
(
b
)
size
=
(
(
a_count
-
1
)
+
(
b_count
-
1
)
+
1
)
size
=
(
a_count
-
1
)
+
(
b_count
-
1
)
+
1
c
=
[
0
]
*
size
for
i
in
range
(
a_count
):
for
j
in
range
(
b_count
):
c
[
i
+
j
]
+=
a
[
i
]
*
b
[
j
]
c
[
i
+
j
]
+=
a
[
i
]
*
b
[
j
]
return
Polynomial
(
tuple
(
c
))
...
...
@@ -94,22 +93,31 @@ class Polynomial:
def
compute_bachet_bezout
(
a
,
b
):
r
=
[]
x
=
[]
y
=
[]
q
=
[]
# Init
r
.
append
(
a
)
x
.
append
(
1
)
y
.
append
(
0
)
q
.
append
(
0
)
r
=
[
a
,
b
]
x
=
[
1
,
0
]
y
=
[
0
,
1
]
q
=
[
0
,
0
]
r
.
append
(
b
)
x
.
append
(
0
)
y
.
append
(
1
)
q
.
append
(
0
)
# Computing
i
=
1
while
r
[
i
]
>
0
:
i
+=
1
r
.
append
(
r
[
i
-
2
]
%
r
[
i
-
1
])
q
.
append
(
int
(
r
[
i
-
2
]
/
r
[
i
-
1
]))
r
.
append
(
r
[
i
-
2
]
%
r
[
i
-
1
])
q
.
append
(
int
(
r
[
i
-
2
]
/
r
[
i
-
1
]))
if
r
[
i
]
>
0
:
x
.
append
(
x
[
i
-
2
]
-
q
[
i
]
*
x
[
i
-
1
])
y
.
append
(
y
[
i
-
2
]
-
q
[
i
]
*
y
[
i
-
1
])
x
.
append
(
x
[
i
-
2
]
-
q
[
i
]
*
x
[
i
-
1
])
y
.
append
(
y
[
i
-
2
]
-
q
[
i
]
*
y
[
i
-
1
])
return
x
[
-
1
],
y
[
-
1
]
...
...
@@ -136,53 +144,27 @@ def compute_lagrange_polynomial(points, prime_number):
dividend
=
Polynomial
((
-
points
[
k
][
0
],
1
))
# x - value
poly_li
*=
dividend
divider
*=
(
points
[
i
][
0
]
-
points
[
k
][
0
]
)
divider
*=
points
[
i
][
0
]
-
points
[
k
][
0
]
divider
=
modular_inverse
(
divider
,
prime_number
)
divider
=
1
/
divider
point_yi
=
points
[
i
][
1
]
poly_li
=
poly_li
*
Polynomial
((
divider
,))
*
Polynomial
((
point_yi
,))
lagrange
+=
poly_li
lagrange
%=
prime_number
return
lagrange
def
reed_solomon
(
points
,
data_length
,
last_error_index
,
prime_number
):
pass
return
None
def
main
():
message
=
{
"
data_length
"
:
25
,
"
last_error_index
"
:
23
,
"
prime_number
"
:
401
,
"
points
"
:
[
67
,
101
,
38
,
109
,
101
,
115
,
133
,
118
,
103
,
128
,
62
,
118
,
97
,
156
,
116
,
77
,
49
,
56
,
86
,
112
,
171
,
105
,
176
,
116
,
115
,
183
,
30
,
315
,
368
,
29
,
352
,
54
,
333
,
198
,
139
,
234
,
321
,
92
,
5
,
272
,
396
,
265
,
397
,
386
,
229
,
153
,
276
]}
p1
=
Polynomial
((
5
,
1
,
4
))
p2
=
Polynomial
((
5
,
2
,
3
,
4
))
p3
=
p1
*
p2
# print(p1)
# print(p2)
# print(p3)
# print(p3 % 4)
# print(p3 % 5)
a
=
168
b
=
68
x
,
y
=
compute_bachet_bezout
(
a
,
b
)
print
(
"
Pour les chiffres
"
+
str
(
a
)
+
"
et
"
+
str
(
b
)
+
"
. Les coéfficients de Bachet-Bézout sont :
"
+
str
(
x
)
+
"
et
"
+
str
(
y
))
a
=
3
b
=
7
print
(
"
Inverse modulaire de
"
+
str
(
a
)
+
"
%
"
+
str
(
b
)
+
"
est
"
+
str
(
modular_inverse
(
a
,
b
)))
with
open
(
"
messages.json
"
)
as
f
:
messages
=
json
.
load
(
f
)
print
(
len
(
messages
))
for
message
in
messages
:
points
=
[(
x
,
y
)
for
x
,
y
in
enumerate
(
message
[
"
points
"
])]
corrected_data
=
reed_solomon
(
points
,
message
[
"
data_length
"
],
message
[
"
last_error_index
"
],
message
[
"
prime_number
"
])
print
(
corrected_data
)
break
points
=
[(
x
,
y
)
for
x
,
y
in
enumerate
(
message
[
"
points
"
])]
corrected_data
=
reed_solomon
(
points
,
message
[
"
data_length
"
],
message
[
"
last_error_index
"
],
message
[
"
prime_number
"
])
print
(
corrected_data
)
if
__name__
==
"
__main__
"
:
...
...
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