Ë
    V.jò  ã                   ó8  — d Z ddlZddlZddgZdededefd„Zd	edefd
„Zdededefd„Z	d	edefd„Z
dedefd„Zdededefd„Zedk(  rQ ed«       ddlZ ed«      D ]1  Z ej$                  «       \  ZZer nedz  dk(  sŒ$esŒ' edez  «       Œ3  ed«       yy)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Úreturnc                 ó*   — |dk7  r|| |z  }} |dk7  rŒ| S )zPReturns the greatest common divisor of p and q

    >>> gcd(48, 180)
    12
    r   © )r   r   s     úKC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\rsa/prime.pyÚgcdr      s&   € ð ˆqŠ&Ø�Q˜‘UˆAˆð ˆq‹&à€Hó    Únumberc                 óf   — t         j                  j                  | «      }|dk\  ry|dk\  ry|dk\  ryy)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ÚcommonÚbit_size)r   Úbitsizes     r
   Úget_primality_testing_roundsr   '   s9   € ô �j‰j×!Ñ! &Ó)€Gà�$‚ØØ�$‚ØØ�#‚~Øàr   ÚnÚkc                 óN  — | dk  ry| dz
  }d}|dz  s|dz  }|dz  }|dz  sŒt        |«      D ]u  }t        j                  j                  | dz
  «      dz   }t	        ||| «      }|dk(  s|| dz
  k(  rŒCt        |dz
  «      D ]!  }t	        |d| «      }|dk(  r  y|| dz
  k(  sŒ! Œt  y y)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é   r   r   T)Úranger   ÚrandnumÚrandintÚpow)r   r   ÚdÚrÚ_ÚaÚxs          r
   Úmiller_rabin_primality_testingr&   A   sÏ   € ð" 	ˆ1‚uØð 	
ˆA‰€AØ	€Aà�1ŠuØ	ˆQ‰ˆØ	ˆa‰ˆð �1‹uô
 �1ŽXˆä�K‰K×Ñ  A¡Ó&¨Ñ*ˆä��1�a‹LˆØ�Š6�Q˜!˜a™%’ZØä�q˜1‘u–ˆAÜ�A�q˜!“ˆAØ�AŠvâØ�A˜‘E‹záð ñ ð% ð( r   c                 óT   — | dk  r| dv S | dz  syt        | «      }t        | |dz   «      S )z™Returns True if the number is prime, and False otherwise.

    >>> is_prime(2)
    True
    >>> is_prime(42)
    False
    >>> is_prime(41)
    True
    r   >   r   r   é   r   r   F)r   r&   )r   r   s     r
   Úis_primer)   v   sA   € ð �‚{Ø˜Ð%Ð%ð �QŠJØô 	% VÓ,€Aô *¨&°!°a±%Ó8Ð8r   Únbitsc                 ól   — | dkD  sJ ‚	 t         j                  j                  | «      }t        |«      r|S Œ-)a  Returns 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
    r   )r   r   Úread_random_odd_intr)   )r*   Úintegers     r
   r   r   �   s;   € ð  �1Š9Ðˆ9à
Ü—+‘+×1Ñ1°%Ó8ˆô �GÔØˆNð r   r$   Úbc                 ó$   — t        | |«      }|dk(  S )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   )r$   r.   r!   s      r
   r   r   ¬   s   € ô 	ˆAˆq‹	€AØ�‰6€Mr   Ú__main__z'Running doctests 1000x or until failureiè  éd   z%i timeszDoctests done)Ú__doc__Ú
rsa.commonr   Úrsa.randnumÚ__all__Úintr   r   Úboolr&   r)   r   r   Ú__name__ÚprintÚdoctestr   ÚcountÚtestmodÚfailuresÚtestsr	   r   r
   Ú<module>r?      s  ðñó Û àÐ-Ð
.€ð	ˆ3ð 	�3ð 	˜3ó 	ð¨ð °ó ð42 cð 2¨cð 2°dó 2ðj9�Sð 9˜Tó 9ð4�Cð ˜Có ð8˜Cð  Cð ¨Dó ð ˆzÒÙ	Ð
3Ô4Ûá�t–ˆØ+˜GŸO™OÓ-Ñˆ�5ÙÙà�3‰;˜!Ó¢Ù�*˜uÑ$Õ%ð ñ 
ˆ/Õð r   