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
04f4e37a
Commit
04f4e37a
authored
2 years ago
by
adrian.spycher
Browse files
Options
Downloads
Patches
Plain Diff
optimize fermat_factorization
parent
38cdacc5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
algo.py
+2
-2
2 additions, 2 deletions
algo.py
with
2 additions
and
2 deletions
algo.py
+
2
−
2
View file @
04f4e37a
...
@@ -78,7 +78,7 @@ def exponentiation_rapide(a, exp, n):
...
@@ -78,7 +78,7 @@ def exponentiation_rapide(a, exp, n):
return
int
(
r
)
return
int
(
r
)
def
is_square
(
a
):
def
is_
perfect_
square
(
a
):
"""
Check if a number is a perfect square, based on the
"
Babylonian algorithm
"
(Héron
'
s method) for square root,
"""
Check if a number is a perfect square, based on the
"
Babylonian algorithm
"
(Héron
'
s method) for square root,
from : https://stackoverflow.com/questions/2489435/check-if-a-number-is-a-perfect-square
from : https://stackoverflow.com/questions/2489435/check-if-a-number-is-a-perfect-square
...
@@ -121,7 +121,7 @@ def fermat_factorization(n):
...
@@ -121,7 +121,7 @@ def fermat_factorization(n):
a
=
math
.
ceil
(
math
.
sqrt
(
n
))
# a = 26262277040 (for the key given)
a
=
math
.
ceil
(
math
.
sqrt
(
n
))
# a = 26262277040 (for the key given)
b2
=
a
**
2
-
n
b2
=
a
**
2
-
n
while
(
not
is
_square
(
b2
)):
while
(
(
a
+
int
(
math
.
sqrt
(
b2
)))
*
(
a
-
int
(
math
.
sqrt
(
b2
)))
!=
n
):
# (not is_perfect
_square(b2)):
a
+=
1
a
+=
1
b2
=
a
**
2
-
n
b2
=
a
**
2
-
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