Use sympy for faster factorization if available (#199)

This commit is contained in:
Lonami Exo 2017-08-17 17:37:27 +02:00
parent 7e85a3cda4
commit 9f812d83a9
2 changed files with 14 additions and 2 deletions

View File

@ -127,6 +127,11 @@ There you'll find a list of all the methods, types and available constructors.
More examples are also available under the ``telethon_examples/`` folder. More examples are also available under the ``telethon_examples/`` folder.
If you're using Telethon under ARM, you may want to install ``sympy`` through
``pip`` for a substantial speed-up when generating the keys required to
connect to Telegram (you can of course do this on desktop too). See
`issue #199 <https://github.com/LonamiWebs/Telethon/issues/199>`_ for more.
Common errors Common errors
------------- -------------

View File

@ -1,4 +1,8 @@
from random import randint from random import randint
try:
import sympy.ntheory
except ImportError:
sympy = None
class Factorization: class Factorization:
@ -58,5 +62,8 @@ class Factorization:
@staticmethod @staticmethod
def factorize(pq): def factorize(pq):
"""Factorizes the given number and returns both the divisor and the number divided by the divisor""" """Factorizes the given number and returns both the divisor and the number divided by the divisor"""
if sympy:
return tuple(sympy.ntheory.factorint(pq).keys())
else:
divisor = Factorization.find_small_multiplier_lopatin(pq) divisor = Factorization.find_small_multiplier_lopatin(pq)
return divisor, pq // divisor return divisor, pq // divisor