Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RSA
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
nicolas.albanesi
RSA
Commits
b0eec710
Commit
b0eec710
authored
3 years ago
by
abivarma.kandiah
Browse files
Options
Downloads
Plain Diff
Merge branch '2-create-function-find_p_q' into 'main'
Resolve "Create Function find_p_q" Closes
#2
See merge request
!2
parents
48cbe13d
56b3be89
No related branches found
No related tags found
2 merge requests
!2
Resolve "Create Function find_p_q"
,
!1
Draft: Resolve "Add prime functions"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/euclide.py
+55
-0
55 additions, 0 deletions
src/euclide.py
src/prime.py
+19
-0
19 additions, 0 deletions
src/prime.py
src/private_key.py
+20
-0
20 additions, 0 deletions
src/private_key.py
with
94 additions
and
0 deletions
src/euclide.py
0 → 100644
+
55
−
0
View file @
b0eec710
'''
Description : Calcule le PGCD de deux nombres et leurs
coefficients de bezout
Return : PGCD, Coef de X, Coef de Y
(X est le nombre le plus grand)
'''
def
pgcd_etendu
(
a
,
b
):
a
,
b
=
abs
(
a
),
abs
(
b
)
# On s'assure que le plus grand nombre est a
#if b > a:
#b,a = a,b
# Vérification que le plus petit nombre n'est pas 0
assert
(
not
(
b
==
0
))
r
=
[
None
]
*
100
q
=
[
None
]
*
100
x
=
[
None
]
*
100
y
=
[
None
]
*
100
etape
=
2
# Phase d'initialisation
r
[
0
]
=
a
x
[
0
]
=
1
y
[
0
]
=
0
r
[
1
]
=
b
x
[
1
]
=
0
y
[
1
]
=
1
while
(
r
[
etape
-
1
]
!=
0
):
r
[
etape
]
=
a
%
b
q
[
etape
]
=
a
//
b
x
[
etape
]
=
x
[
etape
-
2
]
-
q
[
etape
]
*
x
[
etape
-
1
]
y
[
etape
]
=
y
[
etape
-
2
]
-
q
[
etape
]
*
y
[
etape
-
1
]
a
,
b
=
b
,
r
[
etape
]
etape
+=
1
return
r
[
etape
-
2
],
x
[
etape
-
2
],
y
[
etape
-
2
]
def
pgcd_etendu_verif
(
a
,
b
,
x
,
y
,
pgcd
):
if
(
pgcd
==
(
a
*
x
+
b
*
y
)):
return
True
return
False
if
__name__
==
'
__main__
'
:
b
=
4991
a
=
1197
print
(
pgcd_etendu
(
a
,
b
))
pgcd
,
x
,
y
=
pgcd_etendu
(
a
,
b
)
print
(
pgcd_etendu_verif
(
a
,
b
,
x
,
y
,
pgcd
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/prime.py
0 → 100644
+
19
−
0
View file @
b0eec710
from
math
import
*
"""
Check wether a number is prime or not
Bruteforcing method
"""
def
isPrimeNumber
(
number
):
if
number
==
1
:
# 1 is not prime
return
False
if
number
==
2
:
# 2 is a prime number
return
True
if
number
>
2
and
number
%
2
==
0
:
# even numbers are not prime
return
False
for
i
in
range
(
3
,
floor
(
sqrt
(
number
)
+
1
),
2
):
if
number
%
i
==
0
:
return
False
return
True
This diff is collapsed.
Click to expand it.
src/private_key.py
0 → 100644
+
20
−
0
View file @
b0eec710
from
prime
import
*
from
euclide
import
*
def
find_p_q
(
n
):
for
p
in
range
(
3
,
int
(
n
/
2
),
2
):
if
(
n
/
p
).
is_integer
():
return
p
,
n
/
p
def
find_private_key
(
p
,
q
,
e
):
z
=
(
p
-
1
)
*
(
q
-
1
)
r
,
x
,
y
=
pgcd_etendu
(
e
,
z
)
return
(
x
%
z
)
if
__name__
==
'
__main__
'
:
n
=
124344401
#Clé publique 1.
e
=
1919
#Clé publique 2.
p
,
q
=
find_p_q
(
n
)
private_key
=
find_private_key
(
p
,
q
,
e
)
#Clé privé
print
(
private_key
)
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