U
    ha                     @   s"   d Z ddlmZ G dd dZdS )z/
This module holds a fast Factorization class.
    )randintc                   @   s(   e Zd ZdZedd Zedd ZdS )FactorizationzB
    Simple module to factorize large numbers really quickly.
    c                 C   sn  |d dkrd|d fS t d|d t d|d t d|d   }}}d } }}d }}	|dkr|}t|D ]}
t|d|| | }qpd}||k r|dkr|}	tt||| D ],}
t|d|| | }|t||  | }q| ||}||7 }q|d9 }qZ||krFt|	d|| | }	| t||	 |}|dkrqFq|||  }}||k rf||fS ||fS )a  
        Factorizes the given large integer.

        Implementation from https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/.

        :param pq: the prime pair pq.
        :return: a tuple containing the two factors p and q.
           r      )r   rangepowminabsgcd)clsZpqycmgrqxZysikp r   A/tmp/pip-unpacked-wheel-c81u5j2r/telethon/crypto/factorization.py	factorize   s2    
.




zFactorization.factorizec                 C   s   |r|| |  } }q | S )z
        Calculates the Greatest Common Divisor.

        :param a: the first number.
        :param b: the second number.
        :return: GCD(a, b)
        r   )abr   r   r   r
   7   s    	zFactorization.gcdN)__name__
__module____qualname____doc__classmethodr   staticmethodr
   r   r   r   r   r      s
   
+r   N)r   randomr   r   r   r   r   r   <module>   s   