o
     j~                     @   s   d Z ddlZddlZddlmZ ddlT ddlmZ G dd dejZ	G dd	 d	e	Z
G d
d dejZi fddZedkrJdd Zejdd dS dS )zSelf-test for Math.Numbers    N)list_test_cases)*)IntegerNativec                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkS )lTestIntegerBasec                 C   s   t d)NzTo be implemented)NotImplementedErrorself r	   b/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Crypto/SelfTest/Math/test_Numbers.pysetUp0   s   zTestIntegerBase.setUpc                 G   s   t | j|S N)mapInteger)r   argr	   r	   r
   Integers3   s   zTestIntegerBase.Integersc           
      C   s   | j }|d}||}|d}| t|d |d}|d}|d}|d}|d}	| || | |d | || | |d | |d | |d | |d | |d | |	d | ||k ||}| || | |d	d k d S )
N   g      ?l    d(	 l d(	   l    l    r   )r   assertRaises
ValueErrorassertEqualassertFalse)
r   r   v1v2v3v4v5v6Zv7Zv8r	   r	   r
   test_init_and_equality6   s.   z&TestIntegerBase.test_init_and_equalityc                 C   s<   |  ddd \}}| t|d | t|dd  d S )Ni     )r   r   intr   r   r   r	   r	   r
   test_conversion_to_intW   s   z&TestIntegerBase.test_conversion_to_intc                 C   sX   |  dddd \}}}| |dk | |dk | |dk | |dd k d S )Nr   ir   r       r   
assertTruer   r   r   r   r   r	   r	   r
   test_equality_with_ints\   s
   z'TestIntegerBase.test_equality_with_intsc                 C   sh   |  ddddd \}}}}| t|dk | t|dk | t|dk | t|d	k d S )
N   r   ir   r    Z200z-20A.  10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376)r   r&   strr   r   r   r   r   r	   r	   r
   test_conversion_to_strc   s
   z&TestIntegerBase.test_conversion_to_strc                 C   s8   |  ddd \}}| t|d | t|d d S )Nr   P   zInteger(-1)z"Integer(1208925819614629174706176))r   r   reprr"   r	   r	   r
   	test_reprj   s   zTestIntegerBase.test_reprc                 C   s*  | j }|d}| d|  |d}| d|  |d}| d|  | d|d | t|jd	 | d
|jdd | d|jddd |d}| d|  | d|jdd | d|d | d|jddd | t|jd |d}| t|j | jt|jdd d S )Nr       r      i  s   s          s   little	byteorders    l   ";3oUs	    "s	   "̻ s
     "
   s
   "̻     bittle)r   r   to_bytesr   r   )r   r   Zv0r   r   r   r   r	   r	   r
   test_conversion_to_byteso   s4   
z(TestIntegerBase.test_conversion_to_bytesc                 C   s   | j }|d}| t|| | d| |d}| d| |d}| d| |dd}| d| |jddd}| d| |jdd	d}| d
| | t|jdd d S )Nr2   r   s    r5   s   r   bigr7   r6         	r<   )r   
from_bytesr&   
isinstancer   r   r   )r   r   r   r   r   r   r   r   r	   r	   r
   test_conversion_from_bytes   s   


z*TestIntegerBase.test_conversion_from_bytesc                 C   s   |  dddd\}}}}| ||k | |dk | ||k | |dk | ||k | ||k | | dd k d S )NY   Z   r   )r   r&   r   r   r,   r	   r	   r
   test_inequality   s   zTestIntegerBase.test_inequalityc                 C   s   |  ddddd\}}}}}| ||k  | |dk  | ||k  | |dk  | ||k  | ||k  | ||k  | ||k  d S N      rG      r%   r   r   r   r   r   r   r	   r	   r
   test_less_than      zTestIntegerBase.test_less_thanc                 C   s   |  ddddd\}}}}}| ||k | |dk | ||k | |dk | ||k | ||k | ||k | ||k d S )NrJ   rK   rL   r%   rM   r	   r	   r
   test_less_than_or_equal   rO   z'TestIntegerBase.test_less_than_or_equalc                 C   s   |  ddddd\}}}}}| ||k | |dk | ||k | ||k | |dk | ||k | ||k | ||k | ||k d S rI   r%   rM   r	   r	   r
   test_more_than   s   zTestIntegerBase.test_more_thanc                 C   sp   |  dddd\}}}}| ||k | |dk | ||k | ||k | |dk | ||k d S )NrJ   rK   rP   r%   r,   r	   r	   r
   test_more_than_or_equal   s   z'TestIntegerBase.test_more_than_or_equalc                 C   s`   |  dddd\}}}}| | | t| | | | t| | | | | d S )Nr   r9   r   rL   )r   r   boolr&   r,   r	   r	   r
   	test_bool   s   


zTestIntegerBase.test_boolc                 C   sb   |  dd  ddddd \}}}}}| |  | |  | |  | |  d S )Nr4   d   r   )r   r&   Zis_negativer   rM   r	   r	   r
   test_is_negative   s
   &z TestIntegerBase.test_is_negativec                 C   s~   |  ddd\}}}| t|| | j | || d | |d d | || d | |d d | |d d d S )N   rF   a   r   rL   i  r   r&   rC   r   r   r'   r	   r	   r
   test_addition      zTestIntegerBase.test_additionc                 C   s~   |  ddd\}}}| t|| | j | || d | |d d | || d | |d d | |d d d S )	NrY   rF   rZ   S   r[   rK   rL   ir\   r'   r	   r	   r
   test_subtraction   r^   z TestIntegerBase.test_subtractionc                 C   sr   |  dddd\}}}}| t|| | j | || d | |d d | |d d | |d d d S )N      rL   r)   rG   i   r\   r,   r	   r	   r
   test_multiplication  s   z#TestIntegerBase.test_multiplicationc                    s   |  dddd \ }}| t | | j | |  d | |d d | |d d | |dd  d | t fdd d S )	Nr4   r:   r   r/   rW   O   c                      s    d S Nr   r	   r	   r   r	   r
   <lambda>      z0TestIntegerBase.test_floor_div.<locals>.<lambda>)r   r&   rC   r   r   r   ZeroDivisionErrorr   r   r   r	   rg   r
   test_floor_div  s   zTestIntegerBase.test_floor_divc                    s   |  ddd\ }}| t | | j |  | d |  d d | |d d |  d d | t fdd | t fd	d d S )
Nr   rb   rP   r4   r5   rL   c                          d S rf   r	   r	   rg   r	   r
   rh     ri   z0TestIntegerBase.test_remainder.<locals>.<lambda>c                      rm   )Nr	   r	   rg   r	   r
   rh     ri   )r   r&   rC   r   r   r   rj   r   rk   r	   rg   r
   test_remainder  s   zTestIntegerBase.test_remainderc                 C   s   |  ddd\}}}| t|| | j | || d | t||d | |d d | t|dd | |d d | |d d | tt|d d S )Nra   r4   rc   @   r   rG   rW   )r   r&   rC   r   r   powr   r   r'   r	   r	   r
   test_simple_exponentiation!  s   z*TestIntegerBase.test_simple_exponentiationc                 C   s   |  ddd\}}}| tt|||| j | t|||d | t|d|d | t||dd | t|ddd | t|ddd | t|ddd d | t|dd d	d
 | tt|dd | tt|dd | tt|dd d S )Nr   rb      rY   r   r5   r   r/   i\ iE  rP   rW   r:   )	r   r&   rC   rq   r   r   r   rj   r   r'   r	   r	   r
   test_modular_exponentiation-  s   z+TestIntegerBase.test_modular_exponentiationc                 C   sF   |  d}|d | |d |  d}|dd | |d d S )Nra   r         r5   )r   Zinplace_powr   r   r   r	   r	   r
   test_inplace_exponentiation=  s   


z+TestIntegerBase.test_inplace_exponentiationc                 C   s   |  dd  ddddd \}}}}}| t|dd  | t|d | t|d | t|d | t|dd  d S )Nr   rV   rc   r   )r   r   absrM   r	   r	   r
   test_absF  s   &zTestIntegerBase.test_absc                 C   sb   |  ddddd \}}}}| t|j | | d | | d | | dd  d S )Nrc   r   1   r9   rV   rY   2   )r   r   r   sqrtr   r,   r	   r	   r
   	test_sqrtN  s
   zTestIntegerBase.test_sqrtc                 C   s  |  t| djd |  t| djd | dddks"J | dddv s.J dD ]"}td|D ]}|d | }| ||}|||| fv sQJ q7q0|  t| djd |  t| d	jd
 | dddv suJ | dddv sJ d S )Nrb   r   r.   r5   )r5   ra   )   rJ   rs      r         %   )   +   /   5   r   r   ra   r9   rn   )ra   rY   ru   )r   r   r   r}   range)r   piZsquareresr	   r	   r
   test_sqrt_moduleV  s   z TestIntegerBase.test_sqrt_modulec                 C   sp   |  dd\}}||7 }| |d |d7 }| |d |d7 }| |d |dd 7 }| |ddd   d S )	Nr9   r)      (   r.   '   r   r    r   r   r"   r	   r	   r
   test_in_place_addq     z!TestIntegerBase.test_in_place_addc                 C   sd   |  dd\}}||8 }| |d |d8 }| |d |d8 }| |d |d8 }| |d	 d S )
Nr9   r)   iirF   i_ iʠi`yij'  r   r"   r	   r	   r
   test_in_place_sub}  s   z!TestIntegerBase.test_in_place_subc                 C   sp   |  dd\}}||9 }| |d |d9 }| |d |d9 }| |d |dd 9 }| |ddd   d S )	Nr4   rb   rv   r   r   rc   ir    r   r"   r	   r	   r
   test_in_place_mul  r   z!TestIntegerBase.test_in_place_mulc                    sl     dd\}}||; } |d |dd ; } |d |d; } |d  fdd} t| d S )	Nr)   rY      r   r    r   c                     s     d} | d; } d S )N	   r   r   )r   r   r	   r
   t     
z0TestIntegerBase.test_in_place_modulus.<locals>.t)r   r   r   rj   )r   r   r   r   r	   r   r
   test_in_place_modulus  s   z%TestIntegerBase.test_in_place_modulusc                 C   s   |  ddd\}}}| t||@ | j | ||@ d | |d@ d | ||@ d | |d@ d | |d@ d | |dd d @ d d S )N   r{   0      r   r    r\   r'   r	   r	   r
   test_and  s   zTestIntegerBase.test_andc                 C   sz   |  ddd\}}}| t||B | j | ||B d | |dB d | ||B d | |dd B dd d  d S )Nrp      r      ir   r    r\   r'   r	   r	   r
   test_or  s    zTestIntegerBase.test_orc                    s   |  ddd\ }}|  d?   | t |? | j |  |? d |  d? d | t fdd |  dd	 ? d | |d? d
 | |dd	 ? d d S )Nru   r5   r   r:   c                      s    d? S Nr.   r	   r	   rg   r	   r
   rh     ri   z2TestIntegerBase.test_right_shift.<locals>.<lambda>r   r    rG   r.   r   r   r&   rC   r   r   r   rk   r	   rg   r
   test_right_shift  s   z TestIntegerBase.test_right_shiftc                    s     ddd\}}}|dL } |d |dL } |d ||L } |d |dL } |d  fdd	} t|  fd
d} d|   fdd} d|  d S )Nru   r5   r   r   r:   ra   rG   c                     s     d} | dL } d S N   r.   r   r   r   r	   r
   l  r   z4TestIntegerBase.test_in_place_right_shift.<locals>.lc                          d} | dd L } | S Nr   r   r    r   r   r   r	   r
   m1     
z5TestIntegerBase.test_in_place_right_shift.<locals>.m1c                     r   )Nr.   r   r    r   r   r   r	   r
   m2  r   z5TestIntegerBase.test_in_place_right_shift.<locals>.m2r.   r   r   r   r   )r   r   r   r   r   r   r   r	   r   r
   test_in_place_right_shift  s   z)TestIntegerBase.test_in_place_right_shiftc                    s   |  ddd\ }}|  d>   | t |> | j |  |> d |  d> d | |d> d | t fdd | t fd	d d S )
Nru   r5   r   r       c                      s    d> S r   r	   r	   rg   r	   r
   rh     ri   z2TestIntegerBase._test_left_shift.<locals>.<lambda>c                      s    dd > S )Nr   r    r	   r	   rg   r	   r
   rh         r   rk   r	   rg   r
   _test_left_shift  s   z TestIntegerBase._test_left_shiftc                    s     ddd\}}}|dK } |d |dK } |d ||K } |d |dK } |d  fdd	} t|  fd
d} t| d S )Nru   r5   r   r   r   rp   r   c                     s     d} | dK } d S r   r   r   r   r	   r
   r     r   z3TestIntegerBase.test_in_place_left_shift.<locals>.lc                     s     d} | dd K } d S r   r   r   r   r	   r
   m  s   
z3TestIntegerBase.test_in_place_left_shift.<locals>.mr   )r   r   r   r   r   r   r	   r   r
   test_in_place_left_shift  s   z(TestIntegerBase.test_in_place_left_shiftc                 C   s   |  ddd\}}}| |dd | |dd | ||d | |dd | |dd | t|jd | |dd	 d | t|jd | t|jd | t|jd | t|jd
 d S )Ni  rW   r5   r   r:   r   r.   r   r    i  )r   r   Zget_bitr   r   r'   r	   r	   r
   test_get_bit  s   zTestIntegerBase.test_get_bitc                 C   s   |  ddddd\}}}}}| |  | |  | |  | |  | |  | |  | |  | |  | |  | |  d S )Nr   ra   rs   rP   i)r   r&   Zis_evenr   Zis_oddrM   r	   r	   r
   test_odd_even  s   zTestIntegerBase.test_odd_evenc                 C   sZ   |  dddd\}}}}| | d | | d | | d | t|j d S )Nr   r5   r@   r;   r   )r   r   size_in_bitsr   r   r,   r	   r	   r
   test_size_in_bits  s
   z!TestIntegerBase.test_size_in_bitsc                 C   s   |  dddddd\}}}}}}| | d | | d | | d | | d | | d | t|j d S )	Nr   r5      i  i   r   r   r4   )r   r   Zsize_in_bytesr   r   r   r   r   r   r   r   r   r   r	   r	   r
   test_size_in_bytes  s    z"TestIntegerBase.test_size_in_bytesc                 C   s   |  | d  | | d  | | d  |  | d  |  | d  | | d  | | d  |  | d  td	d
D ]}|  | |d d   | | |d   qUd S )Nr   r   r5   r   r4   ra   i  i  rV   r    )r   r   Zis_perfect_squarer&   r   )r   xr	   r	   r
   test_perfect_square'  s   z#TestIntegerBase.test_perfect_squarec                 C   sZ   |  ddd\}}}|d |d |dd  | t|jd | t|j| d S )N   ira   rY   r   r/   )r   Zfail_if_divisible_byr   r   r'   r	   r	   r
   test_fail_if_divisible_by6  s   

z)TestIntegerBase.test_fail_if_divisible_byc                 C   s   |  ddd\}}}||| | |d ||d | |d |d| | |d |dd | |d	 |dd | |d
 |ddd  | |d
dd   |dd d | |d
dd   d S )Nra   r4   r   r9   ru      r5   rc   r)      r      )r   Zmultiply_accumulater   r'   r	   r	   r
   test_multiply_accumulateB  s   z(TestIntegerBase.test_multiply_accumulatec                 C   st   |  dd\}}|| | |d |d | |d |d | |d |dd  | |dd  d S )Nr4   r   r   rc   r   r    )r   setr   r"   r	   r	   r
   test_setS  s   


zTestIntegerBase.test_setc                 C   s   |  dddddd\}}}}}}| t||| j | ||d | |dd | |dd | |dd	 | |d
d | t|jd | t|jd | t|jd | t|jd d S )Nr   rb   rW   r   i ii  r4   iiKS~i&  i  r9   )	r   r&   rC   Zinverser   r   r   r   rj   r   r	   r	   r
   test_inverse^  s    zTestIntegerBase.test_inversec                 C   s*   |  dd\}}|| | |d d S )Nr   rb   r4   )r   Zinplace_inverser   r"   r	   r	   r
   test_inplace_inversem  s   
z$TestIntegerBase.test_inplace_inversec                 C   s   |  dddd\}}}}| t||| j | ||d | |dd | ||d | |dd | |dd d S )Nr   r9   rs   rc   r   r5   )r   r&   rC   gcdr   r   r,   r	   r	   r
   test_gcds  s   zTestIntegerBase.test_gcdc                 C   s   |  ddddd\}}}}}| t||| j | ||d | |dd | ||d | |dd | |dd | |dd | |dd d S )Nr   r9   rs   rc   r   r   f   )r   r&   rC   lcmr   r   rM   r	   r	   r
   test_lcm|  s   zTestIntegerBase.test_lcmc              	   C   sF  d}| j j}tddD ]}| ||dd qtdddD ]}| |d|d q| t|dd | t|dd | t|dd | t|dd | t|dd | t|dd	 | t|dd | t|dd
 |D ]5}| ||d |d |d  | ||  |d |d |d  | ||d |  |d |d  qkd S )N))r   r5   r5   )r   -   r5   )r:      r.   )rb   r   r5   )ib  i  r.   )r   i&  r.   )rb   l   -& r.   r5   r   r   r   rc   r.   r   ra   r:   )r   jacobi_symbolr   r   r   r   )r   datajskntvr	   r	   r
   test_jacobi_symbol  s&   
$&z"TestIntegerBase.test_jacobi_symbolc                 C   s   dg dfdg dfdg dfdg dfd	g d
fdg dfdg dfdg dfdg dfdg dfdg dfdg dfdg dfdg dfg}| j j}|D ]\}}|D ]\}}| |||| qTqNd S )Nr4   )r5   r5   r   r.   r4   r   ra   r5   rb   r.   r   r   rY   r5   r:   r.   r   r   r9   r5   r   r.   r   r   rJ   r5   rK   r.   rv   r   ru   r5   rs   r.   r   r   r   r5   r)   r.   r   r   r   r5   r   r.   r$   r      r5      r.      r      r5   r   r.   r   r   rb   )r   r   r4   r.   r   rb   r   r   r5   rY   r.   r   r   r5   r9   r   r   r5   r   r.   rJ   r.   rK   r5   r   r   r   r   r.   r   r)   r   r   r5   r   r.   r   r$   r5   r   r   r   r5   r   r.   r   r.   r   r5   r   rY   )r   r   r5   r   r   r   r   r.   rY   r   r:   r5   r   r9   r.   r  r  r  rK   r   rv   r5   r   r   r   r5   r   r.   r   r   r   r   r5   r$   r.   r   r   r  r   r   r  r   r5   r   )r   r  r   r   rb   r5   r   r   r  r   r   r  r   r   r  r   r   rs   r5   r   r   r)   r5   r   r   r  r   r   r  r   r   r  r   r   )r   r   r4   r5   r   r  r  r   r   r   r  )r   r   r   r5   r  r  r  r   r   r  r  r  r   r.   )r   r   r  r  r   r  r   r5   r  r   r   r.   rJ   )r   r   r  r   r   r  r   r   r   r   r   r   )rJ   r   r  rv   r.   r   r  r  r  r   r!  r   r  r  r   )r   r   r"  r  r  r  rv   )r   r  r   r   r   r   r   r  r   r   r   r   r  r   r   r   r  r   r   r  r   r  r  r   r
  r   r   r  r   r   rs   )r   r  r   r   r   r  r   r  r   r  r   r  r   r   r  r   )rs   r   r  r   r   r  r  r   r  r   r  r  r  r   r  r   )r   r   r   r   r  r   r   r   r   r  r  r  r  r   r$  r   r  r  )r   r   r  r!  r  r  r	  r   r  r  r   r   r  r   )r   r   r   r   r  r   r  r   r   r  r   r   r  r  r   r   r  r   r  r  r   r   r   r   r   r  r   r  r   r   r   )r   r  r  r   r   r   r   r  r   r  r   r   r   r   r$  r   r   r  r  r   r!  r  )r   r   r	  r   r  r"  r  r  r#  r   )r   r  r  r   r   r   r   r  r   r   r  r   r   r  r   r   r  r  r   r  r  r   r  r	  r
  r  r"  r   r  r   r   r   )r   r   r   r   r  r   r   r   r   r  r   r  r   r   r$  r   r   r  r  r  r!  r   r  r	  r   r   r  r   )r   r   r  )r   r   r   )r   r   r   r   Zkjr   jr	   r	   r
   test_jacobi_symbol_wikipedia  s*   













z,TestIntegerBase.test_jacobi_symbol_wikipediac                 C   s    |  d\}| t|d d S )Nru   Z0x10)r   r   hexrw   r	   r	   r
   test_hex  s   zTestIntegerBase.test_hexc                 C   s   | j j}|ddd}| |d |ddd}| |d |ddd}| |d |ddd}| |d |ddd}| |d d	d
 d }dd }dd }d}| ||||| | t|ddd | t|ddd | t|ddd d S )Nra   rb   r      r   ir   r$   r   i   r5   rJ   rV   rs   s@   (ynpqB,f)Z*r}q:'z8%	[CUE2:r   r.   )r   Z_mult_modulo_bytesr   r   rj   r   )r   Zmodmultr   modulust1t2expectr	   r	   r
   test_mult_modulo_bytes  s&   z&TestIntegerBase.test_mult_modulo_bytesN)8__name__
__module____qualname__r   r   r   r#   r(   r-   r1   r>   rD   rH   rN   rQ   rR   rS   rU   rX   r]   r`   rd   rl   ro   rr   rt   rx   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&  r(  r.  r	   r	   r	   r
   r   .   sl    !
	

			

		#r   c                   @   s   e Zd Zdd ZdS )TestIntegerIntc                 C   s
   t | _d S r   )r   r   r   r	   r	   r
   r        
zTestIntegerInt.setUpNr/  r0  r1  r   r	   r	   r	   r
   r2    s    r2  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
testIntegerRandomc                 C   s~   t dD ]}tjdd}| |dk  | |dk qt ddD ]}tj|d}| |d|d	  k  | |d| k q d S )
Nr    r:   )
exact_bits   r@   rL     r   r5   )r   r   randomr   )r   _a
bits_valuer	   r	   r
   test_random_exact_bits  s   z(testIntegerRandom.test_random_exact_bitsc                 C   st   d}t dD ]}tjdd}|p|dk }| |dk q| | t ddD ]}tj|d}| |d	| k q&d S )
NFr    r:   )Zmax_bitsr7  r@   rL   r8  r   )r   r   r9  r   r&   )r   flagr:  r;  r<  r	   r	   r
   test_random_max_bits  s   
z&testIntegerRandom.test_random_max_bitsc                 C   s6   G dd dt }| }tjd|d}| |jd d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z@testIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNGc                 S   s
   d| _ d S rf   )counterr   r	   r	   r
   __init__	  r3  zItestIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNG.__init__c                 S   s   |  j |7  _ td| S rf   )r@  Zbchr)r   sizer	   r	   r
   __call__  s   zItestIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNG.__call__N)r/  r0  r1  rA  rC  r	   r	   r	   r
   	CustomRNG  s    rD  r   )r6  Zrandfuncra   )objectr   r9  r   r@  )r   rD  Z
custom_rngr;  r	   r	   r
   test_random_bits_custom_rng  s   z-testIntegerRandom.test_random_bits_custom_rngc                 C   s   t j}tdD ]}|ddd}| d|  kodkn   qtdD ]}|ddd}| d|  ko6dk n   q#| jt|dddd | jt|ddd	 d S )
N   r5   rv   )min_inclusivemax_inclusive)rH  max_exclusiver   r4   )rH  rI  rJ  )rI  rJ  )r   Zrandom_ranger   r&   r   r   )r   funcr   r;  r	   r	   r
   test_random_range  s     z#testIntegerRandom.test_random_rangeN)r/  r0  r1  r=  r?  rF  rL  r	   r	   r	   r
   r5    s
    r5  c              
      s  g }|t t7 }zddlm G fdddt}|t |7 }W n* ttfyJ } ztjdkr6tj	
d n
tj	
dt|  W Y d }~nd }~ww zddlm  G  fd	d
d
t}|t |7 }W n ttfy } ztj	
dt|  W Y d }~nd }~ww |t t7 }|S )Nr   
IntegerGMPc                          e Zd Z fddZdS )z!get_tests.<locals>.TestIntegerGMPc                    
    | _ d S r   r   r   rM  r	   r
   r   ,  r3  z'get_tests.<locals>.TestIntegerGMP.setUpNr4  r	   rM  r	   r
   TestIntegerGMP+      rQ  win32zSkipping GMP tests on Windows
zSkipping GMP tests (%s)
IntegerCustomc                       rO  )z*get_tests.<locals>.TestIntegerCustomModexpc                    rP  r   r   r   rT  r	   r
   r   :  r3  z0get_tests.<locals>.TestIntegerCustomModexp.setUpNr4  r	   rT  r	   r
   TestIntegerCustomModexp9  rR  rV  z"Skipping custom modexp tests (%s)
)r   r2  ZCrypto.Math._IntegerGMPrN  r   ImportErrorOSErrorsysplatformstdoutwriter+   ZCrypto.Math._IntegerCustomrU  r5  )configZtestsrQ  erV  r	   )rU  rN  r
   	get_tests$  s,   
 r_  __main__c                   C   s   t t S r   )unittestZ	TestSuiter_  r	   r	   r	   r
   rh   E  r   rh   suite)ZdefaultTest)__doc__rY  ra  ZCrypto.SelfTest.st_commonr   ZCrypto.Util.py3compatZCrypto.Math._IntegerNativer   ZTestCaser   r2  r5  r_  r/  rb  mainr	   r	   r	   r
   <module>   s&   !     <9 