From 9f812d83a93acf121a33da449b41b4d43876fa65 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 17 Aug 2017 17:37:27 +0200 Subject: [PATCH] Use sympy for faster factorization if available (#199) --- README.rst | 5 +++++ telethon/crypto/factorization.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index aa5a8290..10ea7ee9 100755 --- a/README.rst +++ b/README.rst @@ -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. +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 `_ for more. + Common errors ------------- diff --git a/telethon/crypto/factorization.py b/telethon/crypto/factorization.py index e6601f5a..12a03af3 100644 --- a/telethon/crypto/factorization.py +++ b/telethon/crypto/factorization.py @@ -1,4 +1,8 @@ from random import randint +try: + import sympy.ntheory +except ImportError: + sympy = None class Factorization: @@ -58,5 +62,8 @@ class Factorization: @staticmethod def factorize(pq): """Factorizes the given number and returns both the divisor and the number divided by the divisor""" - divisor = Factorization.find_small_multiplier_lopatin(pq) - return divisor, pq // divisor + if sympy: + return tuple(sympy.ntheory.factorint(pq).keys()) + else: + divisor = Factorization.find_small_multiplier_lopatin(pq) + return divisor, pq // divisor