Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ricardo.dossanto1
tp_RSA
Commits
2ba5f6ec
Commit
2ba5f6ec
authored
Jan 17, 2022
by
Elena Biasi
Browse files
ajout fonctions
parent
44ce0d1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
rsa.py
View file @
2ba5f6ec
...
...
@@ -123,14 +123,25 @@ def EuclideEtendu(a,b):
return
u1
,
v1
def
inverseMod
(
x
,
b
):
return
(
x
%
b
+
b
)
%
b
return
(
x
%
b
+
b
)
%
b
def
lpowmod
(
x
,
y
,
n
):
"""puissance modulaire: (x**y)%n avec x, y et n entiers"""
result
=
1
while
y
>
0
:
if
y
&
1
>
0
:
result
=
(
result
*
x
)
%
n
y
>>=
1
x
=
(
x
*
x
)
%
n
return
result
p
,
q
=
EuclideEtendu2
(
n
,
e
,
1
,
0
,
0
,
1
)
nPrime
=
(
p
-
1
)
*
(
q
-
1
)
d
=
inverseMod
(
e
,
nPrime
)
d
=
inverseMod
(
nPrime
,
e
)
print
(
d
)
d
*=
-
1
for
k
in
range
(
len
(
messages
)):
tmp
=
inverseMod
(
int
(
pow
(
messages
[
k
],
d
))
,
n
)
tmp
=
inverseMod
(
n
,
lpowmod
(
messages
[
k
],
d
,
n
)
)
print
(
tmp
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment