mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-01 02:39:54 +03:00
Make code the way I like it
This commit is contained in:
parent
d3febe0e8c
commit
a19d05cd12
|
@ -2,17 +2,10 @@ from random import randint
|
||||||
|
|
||||||
|
|
||||||
class Factorization:
|
class Factorization:
|
||||||
@staticmethod
|
|
||||||
def gcd(a: int, b: int) -> int:
|
|
||||||
while b:
|
|
||||||
a, b = b, a % b
|
|
||||||
|
|
||||||
return a
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def factorize(cls, pq: int) -> tuple or int:
|
def factorize(cls, pq):
|
||||||
if pq % 2 == 0:
|
if pq % 2 == 0:
|
||||||
return 2
|
return 2, pq // 2
|
||||||
|
|
||||||
y, c, m = randint(1, pq - 1), randint(1, pq - 1), randint(1, pq - 1)
|
y, c, m = randint(1, pq - 1), randint(1, pq - 1), randint(1, pq - 1)
|
||||||
g = r = q = 1
|
g = r = q = 1
|
||||||
|
@ -20,15 +13,12 @@ class Factorization:
|
||||||
|
|
||||||
while g == 1:
|
while g == 1:
|
||||||
x = y
|
x = y
|
||||||
|
|
||||||
for i in range(r):
|
for i in range(r):
|
||||||
y = (pow(y, 2, pq) + c) % pq
|
y = (pow(y, 2, pq) + c) % pq
|
||||||
|
|
||||||
k = 0
|
k = 0
|
||||||
|
|
||||||
while k < r and g == 1:
|
while k < r and g == 1:
|
||||||
ys = y
|
ys = y
|
||||||
|
|
||||||
for i in range(min(m, r - k)):
|
for i in range(min(m, r - k)):
|
||||||
y = (pow(y, 2, pq) + c) % pq
|
y = (pow(y, 2, pq) + c) % pq
|
||||||
q = q * (abs(x - y)) % pq
|
q = q * (abs(x - y)) % pq
|
||||||
|
@ -42,8 +32,14 @@ class Factorization:
|
||||||
while True:
|
while True:
|
||||||
ys = (pow(ys, 2, pq) + c) % pq
|
ys = (pow(ys, 2, pq) + c) % pq
|
||||||
g = cls.gcd(abs(x - ys), pq)
|
g = cls.gcd(abs(x - ys), pq)
|
||||||
|
|
||||||
if g > 1:
|
if g > 1:
|
||||||
break
|
break
|
||||||
|
|
||||||
return g, pq // g
|
return g, pq // g
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def gcd(a, b):
|
||||||
|
while b:
|
||||||
|
a, b = b, a % b
|
||||||
|
|
||||||
|
return a
|
||||||
|
|
Loading…
Reference in New Issue
Block a user