o
    ýÞh	  ã                   @   sÀ   d Z ddlZddlmZ ddlZddlZdededdfdd„Z	ded	edefd
d„Z
dgZedkr^edƒ ddlZedƒD ]Ze ¡ \ZZerI ned dkrWerWede ƒ q=edƒ dS dS )z„Functions for parallel computation on multiple cores.

Introduced in Python-RSA 3.1.

.. note::

    Requires Python 2.6 or newer.

é    N)Ú
ConnectionÚnbitsÚpipeÚreturnc                 C   s*   	 t j | ¡}t j |¡r| |¡ d S q)N)ÚrsaÚrandnumÚread_random_odd_intÚprimeÚis_primeÚsend)r   r   Úinteger© r   úL/var/www/html/premium_crap/venv/lib/python3.10/site-packages/rsa/parallel.pyÚ_find_prime    s   
úr   Úpoolsizec                    s€   t jdd�\}‰z#‡ ‡fdd„t|ƒD ƒ}|D ]}| ¡  q| ¡ }W | ¡  ˆ ¡  n	| ¡  ˆ ¡  w |D ]}| ¡  q7|S )aU  Returns a prime number that can be stored in 'nbits' bits.

    Works in multiple threads at the same time.

    >>> p = getprime(128, 3)
    >>> rsa.prime.is_prime(p-1)
    False
    >>> rsa.prime.is_prime(p)
    True
    >>> rsa.prime.is_prime(p+1)
    False

    >>> from rsa import common
    >>> common.bit_size(p) == 128
    True

    F)Úduplexc                    s   g | ]}t jtˆ ˆfd �‘qS ))ÚtargetÚargs)ÚmpÚProcessr   )Ú.0Ú_©r   Ú	pipe_sendr   r   Ú
<listcomp>A   s    zgetprime.<locals>.<listcomp>)r   ÚPipeÚrangeÚstartÚrecvÚcloseÚ	terminate)r   r   Ú	pipe_recvÚprocsÚpÚresultr   r   r   Úgetprime*   s   


ÿ

r%   Ú__main__z'Running doctests 1000x or until failureéd   é
   z%i timeszDoctests done)Ú__doc__Úmultiprocessingr   Úmultiprocessing.connectionr   Ú	rsa.primer   Úrsa.randnumÚintr   r%   Ú__all__Ú__name__ÚprintÚdoctestr   ÚcountÚtestmodÚfailuresÚtestsr   r   r   r   Ú<module>   s(   

(€ô