mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Use sympy for faster factorization if available (#199)
This commit is contained in:
		
							parent
							
								
									7e85a3cda4
								
							
						
					
					
						commit
						9f812d83a9
					
				| 
						 | 
					@ -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
 | 
				
			||||||
-------------
 | 
					-------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user