HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/rsa/__pycache__/prime.cpython-36.pyc
3

%
�a��@s�dZddlZddlZddgZeeed�dd�Zeed�d	d
�Zeeed�dd
�Z	eed�dd�Z
eed�dd�Zeeed�dd�Ze
dkr�ed�ddlZx>ed�D]2Zej�\ZZer�Peddkr�er�ede�q�Wed�dS)z�Numerical functions related to primes.

Implementation based on the book Algorithm Design by Michael T. Goodrich and
Roberto Tamassia, 2002.
�N�getprime�are_relatively_prime)�p�q�returncCs x|dkr|||}}qW|S)zPReturns the greatest common divisor of p and q

    >>> gcd(48, 180)
    12
    r�)rrrr�/usr/lib/python3.6/prime.py�gcds
r	)�numberrcCs4tjj|�}|dkrdS|dkr$dS|dkr0dSdS)a�Returns minimum number of rounds for Miller-Rabing primality testing,
    based on number bitsize.

    According to NIST FIPS 186-4, Appendix C, Table C.3, minimum number of
    rounds of M-R testing, using an error probability of 2 ** (-100), for
    different p, q bitsizes are:
      * p, q bitsize: 512; rounds: 7
      * p, q bitsize: 1024; rounds: 4
      * p, q bitsize: 1536; rounds: 3
    See: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
    i�i�i��
)�rsa�commonZbit_size)r
Zbitsizerrr�get_primality_testing_rounds'sr)�n�krcCs�|dkrdS|d}d}x|d@s4|d7}|dL}qWx�t|�D]z}tjj|d�d}t|||�}|dks@||dkrzq@x>t|d�D]*}t|d|�}|dkr�dS||dkr�Pq�WdSq@WdS)a.Calculates whether n is composite (which is always correct) or prime
    (which theoretically is incorrect with error probability 4**-k), by
    applying Miller-Rabin primality testing.

    For reference and implementation example, see:
    https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test

    :param n: Integer to be tested for primality.
    :type n: int
    :param k: Number of rounds (witnesses) of Miller-Rabin testing.
    :type k: int
    :return: False if the number is composite, True if it's probably prime.
    :rtype: bool
    �F�rrT)�ranger�randnumZrandint�pow)rr�d�r�_�a�xrrr�miller_rabin_primality_testingAs(
rcCs2|dkr|dkS|d@sdSt|�}t||d�S)	z�Returns True if the number is prime, and False otherwise.

    >>> is_prime(2)
    True
    >>> is_prime(42)
    False
    >>> is_prime(41)
    True
    rrr�r
rF>rrrr
)rr)r
rrrr�is_primevsr )�nbitsrcCs.|dkst�xtjj|�}t|�r|SqWdS)aReturns a prime number that can be stored in 'nbits' bits.

    >>> p = getprime(128)
    >>> is_prime(p-1)
    False
    >>> is_prime(p)
    True
    >>> is_prime(p+1)
    False

    >>> from rsa import common
    >>> common.bit_size(p) == 128
    True
    rN)�AssertionErrorrrZread_random_odd_intr )r!Zintegerrrrr�s
)r�brcCst||�}|dkS)z�Returns True if a and b are relatively prime, and False if they
    are not.

    >>> are_relatively_prime(2, 3)
    True
    >>> are_relatively_prime(2, 4)
    False
    r)r	)rr#rrrrr�s

�__main__z'Running doctests 1000x or until failurei��dz%i timesz
Doctests done)�__doc__Z
rsa.commonrZrsa.randnum�__all__�intr	r�boolrr rr�__name__�printZdoctestr�countZtestmodZfailuresZtestsrrrr�<module>s&5