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
b71e690f
Commit
b71e690f
authored
2 years ago
by
adrian.spycher
Browse files
Options
Downloads
Patches
Plain Diff
force some float in int
parent
f4988cf0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
algo.py
+3
-3
3 additions, 3 deletions
algo.py
main.py
+16
-19
16 additions, 19 deletions
main.py
with
19 additions
and
22 deletions
algo.py
+
3
−
3
View file @
b71e690f
...
@@ -56,7 +56,7 @@ def exponentiation_rapide(a, exp, n):
...
@@ -56,7 +56,7 @@ def exponentiation_rapide(a, exp, n):
n (uint): the modulo
n (uint): the modulo
Returns:
Returns:
uint:
An array with the pgdc and the coefficients of bachet_bezout, [pgdc, u, v]
uint:
The result of of the quick explanation
"""
"""
if
(
a
==
0
):
if
(
a
==
0
):
...
@@ -72,7 +72,7 @@ def exponentiation_rapide(a, exp, n):
...
@@ -72,7 +72,7 @@ def exponentiation_rapide(a, exp, n):
b
=
(
b
**
2
)
%
n
b
=
(
b
**
2
)
%
n
exp
=
exp
//
2
exp
=
exp
//
2
return
r
return
int
(
r
)
def
is_square
(
a
):
def
is_square
(
a
):
"""
Check if a number is a perfect square, using the Newton methode
"""
Check if a number is a perfect square, using the Newton methode
...
@@ -115,7 +115,7 @@ def fermat_factorization(n):
...
@@ -115,7 +115,7 @@ def fermat_factorization(n):
b2
=
a
**
2
-
n
b2
=
a
**
2
-
n
if
(
is_square
(
b2
)):
if
(
is_square
(
b2
)):
b
=
math
.
sqrt
(
b2
)
b
=
int
(
math
.
sqrt
(
b2
)
)
break
break
a
+=
1
a
+=
1
...
...
This diff is collapsed.
Click to expand it.
main.py
+
16
−
19
View file @
b71e690f
from
ast
import
For
,
arguments
,
parse
from
cProfile
import
label
from
operator
import
truediv
import
sys
from
algo
import
*
from
algo
import
*
def
main
():
def
main
():
mu
=
{
mu
=
[
416687707
,
416687707
,
420774592
,
420774592
,
1078076801
,
1078076801
,
...
@@ -29,16 +25,17 @@ def main():
...
@@ -29,16 +25,17 @@ def main():
1895548977
,
1895548977
,
1274512749
,
1274512749
,
712992858
712992858
}
#encrypted message
]
#
encrypted message
n
=
1989929159
# first element public key
n
=
1989929159
# first element public key
e
=
2203
# second element public key
e
=
2203
# second element public key
length
=
len
gth
(
mu
)
length
=
len
(
mu
)
# --- private element ---
# --- private element ---
M
=
[]
# decriypted message
M
=
[]
# decriypted message
msg
=
""
# message (string)
msg
=
""
# message (string)
p
,
q
=
0
#primes numbers
p
=
0
# fisrt prime number
q
=
0
# second prime number
d
=
0
# private key
d
=
0
# private key
#--- crack RSA ---
#--- crack RSA ---
...
@@ -47,17 +44,17 @@ def main():
...
@@ -47,17 +44,17 @@ def main():
p
=
a
+
b
p
=
a
+
b
q
=
a
-
b
q
=
a
-
b
print
(
n
==
p
*
q
,
"
\n
"
)
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
.
append
(
exponentiation_rapide
(
mu
[
i
],
d
,
n
)
)
for
m
in
M
:
for
m
in
M
:
print
(
decode_msg
(
m
),
end
=
''
)
msg
+=
decode_msg
(
m
)
print
(
"
p, q :
"
,
p
,
q
,
"
\n
fi :
"
,
fi
,
"
\n
d :
"
,
d
,
"
\n
msg :
"
,
msg
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
()
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