Skip to content

Commit 05cd52e

Browse files
committed
Add kraitchik algorithm
1 parent c583c58 commit 05cd52e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

kraitchik.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from gmpy2 import *
2+
3+
def kraitchik(n):
4+
x = isqrt(n)
5+
while True:
6+
k = 1
7+
s = x * x - k * n
8+
while s >= 0:
9+
if is_square(s):
10+
y = isqrt(s)
11+
z = x + y
12+
w = x - y
13+
if z % n != 0 and w % n != 0:
14+
return gcd(z,n),gcd(w,n)
15+
s = x * x - k * n
16+
k += 1
17+
x+=1
18+
19+
print(kraitchik(2041))
20+
print(kraitchik(65537*65539))
21+

0 commit comments

Comments
 (0)