Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp_rsa_python
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
flavio.morrone
tp_rsa_python
Commits
4c33055c
Commit
4c33055c
authored
2 years ago
by
adrian.spycher
Browse files
Options
Downloads
Patches
Plain Diff
add invers_modulaire
parent
d60af533
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
algo.py
+13
-1
13 additions, 1 deletion
algo.py
main.py
+33
-23
33 additions, 23 deletions
main.py
with
46 additions
and
24 deletions
algo.py
+
13
−
1
View file @
4c33055c
...
@@ -34,6 +34,19 @@ def bachet_bezout(a, b):
...
@@ -34,6 +34,19 @@ def bachet_bezout(a, b):
return
a
,
u
[
i
-
2
],
v
[
i
-
2
]
return
a
,
u
[
i
-
2
],
v
[
i
-
2
]
def
inverse_modulaire
(
a
,
n
):
"""
Does the inverse modular of a by n, using Bachet-Bezout
Args:
a (uint): the number
n (uint): the modulo
Returns:
uint: the inverse modular
"""
return
bachet_bezout
(
a
,
n
)[
1
]
def
exponentiation_rapide
(
a
,
exp
,
n
):
def
exponentiation_rapide
(
a
,
exp
,
n
):
"""
Does the quick explanation of a pow x modulo n
"""
Does the quick explanation of a pow x modulo n
...
@@ -108,4 +121,3 @@ def fermat_factorization(n):
...
@@ -108,4 +121,3 @@ def fermat_factorization(n):
a
+=
1
a
+=
1
return
(
a
,
b
)
return
(
a
,
b
)
This diff is collapsed.
Click to expand it.
main.py
+
33
−
23
View file @
4c33055c
import
algo
from
algo
import
*
def
main
():
def
main
():
mu
=
{
mu
=
{
31726849986005826981
,
416687707
,
305966565717393601613
,
420774592
,
61497322861823383198
,
1078076801
,
269645690420162032117
,
372477309
,
155457162093765938384
,
1915438026
,
24931468152962121635
,
306996859
,
138444967690527010216
,
1858268340
,
282789589899417404817
,
1934595642
,
134251529920691060404
,
444729462
,
423054566352157178418
,
1953792398
,
265453042944217161627
,
1118037789
,
39119050384849643825
1220832721
,
701508709
,
1976470330
,
1081245832
,
1480954262
,
921801986
,
1154526486
,
1974597168
,
812527863
,
1895548977
,
1274512749
,
712992858
}
#encrypted message
}
#encrypted message
n
=
1989929159
#first element public key
n
=
4556490129
*
pow
(
10
,
11
)
+
89940178621
#first element public key
e
=
2203
#second element public key
e
=
5303
#second element public key
length
=
length
(
mu
)
length
=
length
(
mu
)
...
@@ -38,7 +48,7 @@ def main():
...
@@ -38,7 +48,7 @@ def main():
fi
=
(
p
-
1
)
*
(
q
-
1
)
fi
=
(
p
-
1
)
*
(
q
-
1
)
d
=
inverse_modulaire
(
e
,
fi
)
d
=
inverse_modulaire
(
e
,
fi
)
#
//
--- decode mu & initialise msg ---
# --- decode mu & initialise msg ---
for
i
in
range
(
length
):
for
i
in
range
(
length
):
M
[
i
]
=
exponentiation_rapide
(
mu
[
i
],
d
,
n
)
M
[
i
]
=
exponentiation_rapide
(
mu
[
i
],
d
,
n
)
...
...
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