
    ,h~                         d Z ddlZddlZddlmZ ddl ddlmZ  G d dej                        Z	 G d d	e	      Z
 G d
 dej                        Zi fdZedk(  rd Z ej                  d       yy)zSelf-test for Math.Numbers    N)list_test_cases)*)IntegerNativec                   J   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7y6)7TestIntegerBasec                     t        d      )NzTo be implemented)NotImplementedErrorselfs    c/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/SelfTest/Math/test_Numbers.pysetUpzTestIntegerBase.setUp0   s    !"566    c                 .    t        | j                  |      S N)mapInteger)r   args     r   IntegerszTestIntegerBase.Integers3   s    4<<%%r   c                    | j                   } |d      } ||      } |d      }| j                  t        |d        |d      } |d      } |d      } |d      } |d      }	| j                  ||       | j                  |d       | j                  ||       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |	d       | j	                  ||k(          ||      }| j                  ||       | j	                   |d	      d k(         y )
N   g      ?l    d(	 l d(	   l    l    r   )r   assertRaises
ValueErrorassertEqualassertFalse)
r   r   v1v2v3v4v5v6v7v8s
             r   test_init_and_equalityz&TestIntegerBase.test_init_and_equality6   s>   ,,R[R[R[*gs3V_WV_Z '(R R R R X&Y'V$Z(/0r" R[R t+,r   c                     | j                  dddz        \  }}| j                  t        |      d       | j                  t        |      ddz         y )Ni     )r   r   intr   r   r   s      r   test_conversion_to_intz&TestIntegerBase.test_conversion_to_intW   sF    sAI.BR#&R!t),r   c                     | j                  ddddz        \  }}}| j                  |dk(         | j                  |dk(         | j                  |dk(         | j                  |ddz  k(         y )Nr   ir'   r(      r   
assertTruer   r   r   r   r   s       r   test_equality_with_intsz'TestIntegerBase.test_equality_with_ints\   sd    ]]2sAI6
Bb!c	"r"a4i(r   c                 $   | j                  dddddz        \  }}}}| j                  t        |      dk(         | j                  t        |      dk(         | j                  t        |      dk(         | j                  t        |      d	k(         y )
N   r   ir'   r(   200z-20.  10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376)r   r/   strr   r   r   r   r    s        r   test_conversion_to_strz&TestIntegerBase.test_conversion_to_strc   s~    r1c19=BBB4(B3'B5()B  $T  T  	Ur   c                     | j                  dddz        \  }}| j                  t        |      d       | j                  t        |      d       y )Nr'   P   zInteger(-1)z"Integer(1208925819614629174706176))r   r   reprr*   s      r   	test_reprzTestIntegerBase.test_reprj   sC    r1b5)Bb=1b#GHr   c                    | j                   } |d      }| j                  d|j                                 |d      }| j                  d|j                                 |d      }| j                  d|j                                | j                  d|j                  d             | j                  t        |j                  d	       | j                  d
|j                  d             | j                  d|j                  dd              |d      }| j                  d|j                                | j                  d|j                  d             | j                  d|j                  d             | j                  d|j                  dd             | j                  t        |j                  d        |d      }| j                  t        |j                         | j                  t        |j                  d       y )Nr       r      i  s   s          s   little	byteorders    l   ";3oUs	    "s	   "̻ s
     "
   s
   "̻     bittle)r   r   to_bytesr   r   )r   r   v0r   r   r   r    s          r   test_conversion_to_bytesz(TestIntegerBase.test_conversion_to_byteso   s   ,,QZ"++-0T]"++-0V_bkkm4"++a.9*bkk15bkkHk&EF"++a8+*LM)*@"++-P@x8	:DR	*DR8<	>*bkk15S\*bkk2*bkkXFr   c                 D   | j                   }|j                  d      }| j                  t        ||             | j	                  d|       |j                  d      }| j	                  d|       |j                  d      }| j	                  d|       |j                  dd      }| j	                  d|       |j                  dd      }| j	                  d|       |j                  dd	      }| j	                  d
|       | j                  t        |j                  dd       y )Nr@   r   s    rC   s   r   bigrE   rD         	rJ   )r   
from_bytesr/   
isinstancer   r   r   )r   r   r   r   r   r    r!   r"   s           r   test_conversion_from_bytesz*TestIntegerBase.test_conversion_from_bytes   s   ,,(
2w/0B,B,$U3Bu=Bx@$*g&8&8'8Lr   c                 l   | j                  dddd      \  }}}}| j                  ||k7         | j                  |dk7         | j                  ||k7         | j                  |dk7         | j                  ||k7         | j                  ||k7         | j                  | j                  d      d k7         y )NY   Z   r   )r   r/   r   r   r8   s        r   test_inequalityzTestIntegerBase.test_inequality   s    r2r26BBb!b!r"r"b!b!Q4/0r   c                 z   | j                  ddddd      \  }}}}}| j                  ||k         | j                  |dk         | j                  ||k         | j                  |dk         | j                  ||k         | j                  ||k         | j                  ||k         | j                  ||k         y N      rX      r.   r   r   r   r   r    r!   s         r   test_less_thanzTestIntegerBase.test_less_than   s    !]]2r2r7CBBR R b!b!R b!R b!r   c                 z   | j                  ddddd      \  }}}}}| j                  ||k         | j                  |dk         | j                  ||k         | j                  |dk         | j                  ||k         | j                  ||k         | j                  ||k         | j                  ||k         y )Nr\   r]   r^   r.   r_   s         r   test_less_than_or_equalz'TestIntegerBase.test_less_than_or_equal   s    !]]2r2r7CBBb!b!b!b!b!r"b!r"r   c                    | j                  ddddd      \  }}}}}| j                  ||kD         | j                  |dkD         | j                  ||kD         | j                  ||kD         | j                  |dkD         | j                  ||kD         | j                  ||kD         | j                  ||kD         | j                  ||kD         y r[   r.   r_   s         r   test_more_thanzTestIntegerBase.test_more_than   s    !]]2r2r7CBBR R b!b!b!R b!R b!r   c                 &   | j                  dddd      \  }}}}| j                  ||k\         | j                  |dk\         | j                  ||k\         | j                  ||k\         | j                  |dk\         | j                  ||k\         y )Nr\   r]   rb   r.   r8   s        r   test_more_than_or_equalz'TestIntegerBase.test_more_than_or_equal   s    r2r26BBb!b!b!b!b!r"r   c                 &   | j                  dddd      \  }}}}| j                  |       | j                  t        |             | j                  |       | j                  t        |             | j                  |       | j                  |       y )Nr   rG   r   r^   )r   r   boolr/   r8   s        r   	test_boolzTestIntegerBase.test_bool   sr    q"b':BBb"R!r   c                 @   | j                  ddz   dddddz        \  }}}}}| j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                y )NrB   d   r   )r   r/   is_negativer   r_   s         r   test_is_negativez TestIntegerBase.test_is_negative   s}    !]]AH9b!Q3GBB()())*)*r   c                 T   | j                  ddd      \  }}}| j                  t        ||z   | j                               | j	                  ||z   d       | j	                  |dz   d       | j	                  ||z   d       | j	                  |dz   d       | j	                  |dz   d       y )N   rW   a   r   r^   i  r   r/   rS   r   r   r0   s       r   test_additionzTestIntegerBase.test_addition   s    ]]1b"-
B
27DLL9:b"%b"%b!$rA&g{3r   c                 T   | j                  ddd      \  }}}| j                  t        ||z
  | j                               | j	                  ||z
  d       | j	                  |dz
  d       | j	                  ||z
  d       | j	                  |dz
  d       | j	                  |dz
  d       y )	Nrq   rW   rr   S   rs   r]   r^   irt   r0   s       r   test_subtractionz TestIntegerBase.test_subtraction   s    ]]1b"-
B
27DLL9:b"%a$b"%rB'g{3r   c                 .   | j                  dddd      \  }}}}| j                  t        ||z  | j                               | j	                  ||z  d       | j	                  |dz  d       | j	                  |dz  d       | j	                  |dz  d       y )N      r^   r3   rX   i   rt   r8   s        r   test_multiplicationz#TestIntegerBase.test_multiplication  s    q!R9BB
27DLL9:b"%a$b"%g}5r   c                 j   | j                  ddddz        \  }}| j                  t        |z  | j                               | j	                  |z  d       | j	                  |dz  d       | j	                  |dz  d       | j	                  |ddz  z  d       | j                  t        fd       y )NrB   rH   r'   r<   rm   O   c                       dz  S Nr    r   s   r   <lambda>z0TestIntegerBase.test_floor_div.<locals>.<lambda>  s    R1W r   )r   r/   rS   r   r   r   ZeroDivisionErrorr   r   r   r   s      @r   test_floor_divzTestIntegerBase.test_floor_div  s    ]]1ab1
B
28T\\:;r1%q!$r2&qBw*+_=r   c                    | j                  ddd      \  }}| j                  t        |z  | j                               | j	                  |z  d       | j	                  dz  d       | j	                  |dz  d       | j	                  dz  d       | j                  t        fd       | j                  t        fd       y )	Nr   r{   rb   rB   rC   r^   c                       dz  S r   r   r   s   r   r   z0TestIntegerBase.test_remainder.<locals>.<lambda>  s    R!V r   c                       dz  S )Nr   r   s   r   r   z0TestIntegerBase.test_remainder.<locals>.<lambda>  s    b2g r   )r   r/   rS   r   r   r   r   r   r   s      @r   test_remainderzTestIntegerBase.test_remainder  s    ]]2q"-
B
27DLL9:b!$a#a#gr*+^<*o6r   c                    | j                  ddd      \  }}}| j                  t        ||z  | j                               | j	                  ||z  d       | j	                  t        ||      d       | j	                  |dz  d       | j	                  t        |d      d       | j	                  |dz  d       | j	                  |dz  d       | j                  t        t
        |d       y )Nrz   rB   r|   @   r'   rX   rm   )r   r/   rS   r   r   powr   r   r0   s       r   test_simple_exponentiationz*TestIntegerBase.test_simple_exponentiation!  s    ]]1a,
B
28T\\:;r2&Rb)q"%RR(q!$q"%*c2r2r   c           	         | j                  ddd      \  }}}| j                  t        t        |||      | j                               | j                  t        |||      d       | j                  t        |d|      d       | j                  t        ||d      d       | j                  t        |dd      d       | j                  t        |dd      d       | j                  t        |dddz        d       | j                  t        |ddz  d	      d
       | j                  t        t        |dd       | j                  t        t        |dd       | j                  t        t        |dd       y )Nr   r{      rq   r   rC   r'   r<   i\ iE  rb   rm   rH   )	r   r/   rS   r   r   r   r   r   r   r0   s       r   test_modular_exponentiationz+TestIntegerBase.test_modular_exponentiation-  s.   ]]2q"-
B
3r2r?DLLABRR!,RR!,RR!,RR!,RR!,RQ"W-r2Rb5159+S"a;*c2q"5*c2r15r   c                     | j                  d      }|j                  d       | j                  |d       | j                  d      }|j                  dd       | j                  |d       y )Nrz   r'         rC   )r   inplace_powr   r   r   s     r   test_inplace_exponentiationz+TestIntegerBase.test_inplace_exponentiation=  sV    \\!_
qR \\!_
q"Qr   c                 b   | j                  ddz   dddddz        \  }}}}}| j                  t        |      ddz         | j                  t        |      d       | j                  t        |      d       | j                  t        |      d       | j                  t        |      ddz         y )Nr'   rl   r|   r   )r   r   absr_   s         r   test_abszTestIntegerBase.test_absF  s    !]]AH9b!QSIBBR!s(+R!$R!$R!$R!s(+r   c                 B   | j                  dddddz        \  }}}}| j                  t        |j                         | j	                  |j                         d       | j	                  |j                         d       | j	                  |j                         ddz         y )Nr|   r   1   rG   rl   rq   2   )r   r   r   sqrtr   r8   s        r   	test_sqrtzTestIntegerBase.test_sqrtN  s|    r1b"c':BB*bgg.A&A&BF+r   c                 <   | j                  t        | j                  d      j                  d       | j                  t        | j                  d      j                  d       | j                  d      j                  d      dk(  sJ | j                  d      j                  d      dv sJ dD ]F  }t	        d|      D ]5  }|dz  |z  }| j                  |      j                  |      }||||z
  fv r5J  H | j                  t        | j                  d      j                  d       | j                  t        | j                  d	      j                  d
       | j                  d      j                  d      dv sJ | j                  d      j                  d      dv sJ y )Nr{   r   r;   rC   )rC   rz   )   r\   r      r         %   )   +   /   5   r'   r   rz   rG   r   )rz   rq   r   )r   r   r   r   range)r   pisquareress        r   test_sqrt_modulez TestIntegerBase.test_sqrt_moduleV  si    	*dll1o&:&:A>*dll1o&:&:B? ||A##A&!++||A##A&&00 B 	)A1a[ )All6*//2q!a%j(()	) 	*dll1o&:&:B? 	*dll1o&:&:B? ||F#((,66||F#((,666r   c                     | j                  dd      \  }}||z  }| j                  |d       |dz  }| j                  |d       |dz  }| j                  |d       |ddz  z  }| j                  |dddz  z          y )	NrG   r3      (   r;   '   r'   r(   r   r   r*   s      r   test_in_place_addz!TestIntegerBase.test_in_place_addq  s    r2&B
bR 
bR 
bR 
a4iR!t)^,r   c                     | j                  dd      \  }}||z  }| j                  |d       |dz  }| j                  |d       |dz  }| j                  |d       |dz  }| j                  |d	       y )
NrG   r3   iirW   i_ iʠi`yij'  r   r*   s      r   test_in_place_subz!TestIntegerBase.test_in_place_sub}  sz    r2&B
bS!
d
R 
eV$
gU#r   c                     | j                  dd      \  }}||z  }| j                  |d       |dz  }| j                  |d       |dz  }| j                  |d       |ddz  z  }| j                  |dddz  z         y )	NrB   r{   r   r'   r   r|   ir(   r   r*   s      r   test_in_place_mulz!TestIntegerBase.test_in_place_mul  s    q!$B
bR 
aR 
bS!
a4iSAI./r   c                       j                  dd      \  }}||z  } j                  |d       |ddz  z  } j                  |d       |dz  } j                  |d        fd} j                  t        |       y )Nr3   rq      r'   r(   r   c                  2    j                  d      } | dz  } y )N	   r   r   )r   r   s    r   tz0TestIntegerBase.test_in_place_modulus.<locals>.t  s    aB!GBr   )r   r   r   r   )r   r   r   r   s   `   r   test_in_place_modulusz%TestIntegerBase.test_in_place_modulus  s~    r1%B
bQ
a4iQ
aQ	 	+Q/r   c                    | j                  ddd      \  }}}| j                  t        ||z  | j                               | j	                  ||z  d       | j	                  |dz  d       | j	                  ||z  d       | j	                  |dz  d       | j	                  |dz  d       | j	                  |ddz  dz   z  d       y )N   r   0      r'   r(   rt   r0   s       r   test_andzTestIntegerBase.test_and  s    ]]4t4
B
27DLL9:b$'dD)b$'dD)dD)qDy4/0$7r   c                 <   | j                  ddd      \  }}}| j                  t        ||z  | j                               | j	                  ||z  d       | j	                  |dz  d       | j	                  ||z  d       | j	                  |ddz  z  ddz  dz          y )Nr      r      ir'   r(   rt   r0   s       r   test_orzTestIntegerBase.test_or  s    ]]4t4
B
27DLL9:b$'dD)b$'a4idT)9:r   c                    | j                  ddd      \  }}| j                  dz	         | j                  t        |z	  | j                               | j                  |z	  d       | j                  dz	  d       | j                  t        fd       | j                  ddz  z	  d       | j                  |dz	  d	       | j                  |ddz  z	  d
       y )Nr   rC   r   rH   c                       dz	  S Nr;   r   r   s   r   r   z2TestIntegerBase.test_right_shift.<locals>.<lambda>      bBh r   r'   r(   rX   r;   r   r   r/   rS   r   r   r   r   s      @r   test_right_shiftz TestIntegerBase.test_right_shift  s    ]]4E2
Bq"%
28T\\:;r4(q$'*&67T	*A.q%(T	*B/r   c                      j                  ddd      \  }}}|dz  } j                  |d       |dz  } j                  |d       ||z  } j                  |d       |dz  } j                  |d        fd} j                  t        |        fd	} j                  d |               fd
} j                  d |              y )Nr   rC   r   r   rH   rz   rX   c                  2    j                  d      } | dz  } y N   r;   r   r    r   s    r   lz4TestIntegerBase.test_in_place_right_shift.<locals>.l      d#B2IBr   c                  :    j                  d      } | ddz  z  } | S Nr   r'   r(   r   r   s    r   m1z5TestIntegerBase.test_in_place_right_shift.<locals>.m1  s$    d#B19BIr   c                  :    j                  d      } | ddz  z  } | S )Nr;   r'   r(   r   r   s    r   m2z5TestIntegerBase.test_in_place_right_shift.<locals>.m2  s$    b!B19BIr   r;   r   r   r   r   )r   r   r   r   r   r   r   s   `      r   test_in_place_right_shiftz)TestIntegerBase.test_in_place_right_shift  s    ]]4E2
B
qT"
qT"
r	T"
qU#	 	*a(	 	BD!	 	RT"r   c                    | j                  ddd      \  }}| j                  dz         | j                  t        |z  | j                               | j                  |z  d       | j                  dz  d       | j                  |dz  d       | j                  t        fd       | j                  t        fd       y )	Nr   rC   r   r       c                       dz  S r   r   r   s   r   r   z2TestIntegerBase._test_left_shift.<locals>.<lambda>  r   r   c                       ddz  z  S )Nr'   r(   r   r   s   r   r   z2TestIntegerBase._test_left_shift.<locals>.<lambda>  s    bQ$Y.? r   r   r   s      @r   _test_left_shiftz TestIntegerBase._test_left_shift  s    ]]4E2
Bq"%
28T\\:;r4(q$'q%(*&67*&?@r   c                 X     j                  ddd      \  }}}|dz  } j                  |d       |dz  } j                  |d       ||z  } j                  |d       |dz  } j                  |d        fd} j                  t        |        fd	} j                  t        |       y )
Nr   rC   r   r   r   r   r   c                  2    j                  d      } | dz  } y r   r   r   s    r   r   z3TestIntegerBase.test_in_place_left_shift.<locals>.l  r   r   c                  8    j                  d      } | ddz  z  } y r   r   r   s    r   mz3TestIntegerBase.test_in_place_left_shift.<locals>.m  s    d#B19Br   r   )r   r   r   r   r   r   s   `     r   test_in_place_left_shiftz(TestIntegerBase.test_in_place_left_shift  s    ]]4E2
B
qT"
qT"
r	T"
qU#	 	*a(	 	*a(r   c                    | j                  ddd      \  }}}| j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  d      d       | j                  t        |j                  d       | j                  |j                  dd	z        d       | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  d
       y )Ni  rm   rC   r   rH   r   r;   r'   r(   i  )r   r   get_bitr   r   r0   s       r   test_get_bitzTestIntegerBase.test_get_bit  s   ]]5"a0
BA*A*B+A*A**bjj"5AI.2*bjj"5*bjj!4*bjj!4*bjj(;r   c                    | j                  ddddd      \  }}}}}| j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j	                                | j                  |j	                                | j                  |j	                                | j                  |j	                                | j                  |j	                                y )Nr   rz   r   rb   i)r   r/   is_evenr   is_oddr_   s         r   test_odd_evenzTestIntegerBase.test_odd_even  s    !]]1aR=BB

%

%&

%&%%		$%		$r   c                 6   | j                  dddd      \  }}}}| j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  t        |j                         y )Nr   rC   rP   rI   r   )r   r   size_in_bitsr   r   r8   s        r   test_size_in_bitsz!TestIntegerBase.test_size_in_bits  sw    q!UC8BB*A.*A.*A.*boo6r   c                    | j                  dddddd      \  }}}}}}| j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  t        |j
                         y )	Nr   rC      i  i   r   r'   rB   )r   r   size_in_bytesr   r   r   r   r   r   r   r    r!   r"   s          r   test_size_in_bytesz"TestIntegerBase.test_size_in_bytes  s    !%q!T5'2!NBBB))+Q/))+Q/))+Q/))+Q/))+Q/*boo6r   c                    | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                | j                  | j                  d      j                                t	        d	d
      D ]g  }| j                  | j                  |dz  dz         j                                | j                  | j                  |dz        j                                i y )Nr   r   rC   r'   rB   rz   i  i  rl   r(   )r   r   is_perfect_squarer/   r   )r   xs     r   test_perfect_squarez#TestIntegerBase.test_perfect_square'  sW   b);;=>Q99;<Q99;<a::<=a::<=Q99;<U+==?@g.@@BCsD! 	DAT\\!Q$q&1CCEFOODLLA.@@BC	Dr   c                 "   | j                  ddd      \  }}}|j                  d       |j                  d       |j                  ddz         | j                  t        |j                  d       | j                  t        |j                  |       y )N   irz   rq   r'   r<   )r   fail_if_divisible_byr   r   r0   s       r   test_fail_if_divisible_byz)TestIntegerBase.test_fail_if_divisible_by6  s|    ]]2sA.
B 	"
"
R( 	*b&=&=qA*b&=&=rBr   c                 N   | j                  ddd      \  }}}|j                  ||       | j                  |d       |j                  |d       | j                  |d       |j                  d|       | j                  |d       |j                  dd       | j                  |d	       |j                  dd       | j                  |d
       |j                  dddz         | j                  |d
ddz  z          |j                  ddz  d       | j                  |d
ddz  z          y )Nrz   rB   r'   rG   r      rC   r|   r3      r(     )r   multiply_accumulater   r0   s       r   test_multiply_accumulatez(TestIntegerBase.test_multiply_accumulateB  s   ]]1a+
B
r2&R 
r1%R 
q"%R 
q"%R 
r1%R 
q!t),R!t)^,
qDy!,R!t)^,r   c                 R   | j                  dd      \  }}|j                  |       | j                  |d       |j                  d       | j                  |d       |j                  d       | j                  |d       |j                  ddz         | j                  |ddz         y )NrB   r   r   r|   r'   r(   )r   setr   r*   s      r   test_setzTestIntegerBase.test_setS  s    q!$B
r
Q
q	Q
r
R 
qDyQ$Y'r   c                    | j                  dddddd      \  }}}}}}| j                  t        |j                  |      | j                               | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d      d	       | j                  |j                  d
      d       | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  d       y )Nr'   r{   rm   r   i ii  rB   iiKS~i&  i  rG   )	r   r/   rS   inverser   r   r   r   r   r   s          r   test_inversezTestIntegerBase.test_inverse^  s   !%q!RFD!IBBB
2::b>4<<@AB+A*A*H-x8D)40*bjj"5*bjj"5*bjj"5+RZZ;r   c                 t    | j                  dd      \  }}|j                  |       | j                  |d       y )Nr'   r{   rB   )r   inplace_inverser   r*   s      r   test_inplace_inversez$TestIntegerBase.test_inplace_inversem  s4    q!$B
2Qr   c                    | j                  dddd      \  }}}}| j                  t        |j                  |      | j                               | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  d      d       y )Nr   rG   r   r|   r'   rC   )r   r/   rS   gcdr   r   r8   s        r   test_gcdzTestIntegerBase.test_gcds  s    q"b"5BB
266":t||<=Q'Q'Q'Q'A&r   c                 p   | j                  ddddd      \  }}}}}| j                  t        |j                  |      | j                               | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  |      d       | j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d      d       y )Nr   rG   r   r|   r   r   f   )r   r/   rS   lcmr   r   r_   s         r   test_lcmzTestIntegerBase.test_lcm|  s    !]]1b"b!<BB
266":t||<=R(R(S)Q'A&A&A&r   c           
      t   d}| j                   j                  }t        dd      D ]  }| j                   ||d      d        t        ddd      D ]  }| j                   |d|      d        | j	                  t
        |dd       | j	                  t
        |dd       | j	                  t
        |dd       | j	                  t
        |dd       | j	                  t
        |dd       | j	                  t
        |dd	       | j	                  t
        |dd       | j	                  t
        |dd
       |D ]  }| j                   ||d   |d         |d          | j                   || j                  |d         |d         |d          | j                   ||d   | j                  |d               |d           y )N))r  rC   rC   )r   -   rC   )rH      r;   )r{   r  rC   )ib  i  r;   )r  i&  r;   )r{   l   -& r;   rC   r   r'   r   r|   r;   r   rz   rH   )r   jacobi_symbolr   r   r   r   )r   datajskntvs         r   test_jacobi_symbolz"TestIntegerBase.test_jacobi_symbol  s    \\'' q" 	*AR1Xq)	*q"a 	*AR1Xq)	* 	*b!R0*b!R0*b!Q/*b!Q/*b!Q/*b!Q/*b!Q/*b!Q/ 	DBR1r!u-r!u5RRU 3RU;RUCR1t||BqE':;RUC	Dr   c                    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 ]  \  }}| j                   |||      |         * y )NrB   )rC   rC   r'   r;   rB   r   rz   rC   r{   r;   r   r   rq   rC   rH   r;   r   r   rG   rC   r   r;   r  r   r\   rC   r]   r;   r   r   r   rC   r   r;   r  r   r   rC   r3   r;   r  r   r  rC   r   r;   r-   r      rC      r;      r      rC   r   r;   r   r   r{   )r%  r&  rB   r;   r(  r{   r   r   rC   rq   r;   r,  r   rC   rG   r   r   rC   r  r;   r\   r;   r]   rC   r3  r4  r5  r  r;   r7  r3   r   r  rC   r  r;   r;  r-   rC   r>  r   r@  rC   rB  r;   rD  r;   r   rC   rF  rq   )r%  r'   rC   rG  r(  r)  r   r;   rq   r   rH   rC   rK  rG   r;   rM  rN  rO  r]   r   r   rC   r4  r5  r  rC   r   r;   r8  r9  r:  r   rC   r-   r;   r=  r?  rX  rD  r   rZ  r   rC   r   )r%  r[  r'  r(  r{   rC   r*  r+  r^  r-  r.  rM  r0  r1  rP  r3  r4  r   rC   r6  r7  r3   rC   r9  r:  rd  r<  r=  rW  rA  rC  rZ  rF  r   )r%  r&  rB   rC   r(  rh  r\  rJ  r,  rK  r_  )r   r   r  rC   rO  rP  ra  r4  r5  rQ  rc  rj  r  r;   )r  r   rd  re  r=  rW  rB  rC   rY  rE  r   r;   r\   )r%  r&  rk  r(  r)  r\  rJ  r,  rK  r.  r/  rl  )r\   r   rP  r   r;   r4  ri  rQ  rc  r8  rm  r:  rd  re  r=  )r@  r   rn  rY  rZ  rg  r   )r%  r[  r'  r(  rH  r*  rJ  r^  r-  rL  r/  r0  rO  r2  r3  r4  ri  r6  r7  rR  r9  rT  rd  r<  rV  r?  rA  rY  rE  rF  r   )r%  r[  rG  r(  r)  r\  rJ  r^  rK  r_  r/  rN  r1  r2  ra  r4  )r   r   rb  r7  r8  rS  rT  r;  re  r=  rW  rX  rY  rE  rg  r   )r%  r&  rG  r(  rh  rI  r+  r,  rK  r_  rM  rN  rO  r2  rp  r4  ri  rQ  )r   r   rj  rm  rT  rd  rU  r=  rW  rX  rC  rE  rg  r  )r%  r&  r'  r(  rh  r*  r]  r,  r-  r_  r/  r0  rO  r`  r3  r4  ri  r6  rc  rj  r9  r:  r;  r<  r=  rW  rA  rf  rE  rF  r   )r%  r[  rk  r(  r)  rI  rJ  r^  rK  r_  r/  rl  r1  r2  rp  r4  r5  rb  rc  r8  rm  rT  )r   r   rU  r=  rW  rn  rY  rZ  ro  r>  )r%  r[  rk  r(  rH  rI  r+  r^  rK  rL  rM  rl  r1  rP  r3  r4  ri  rb  r7  rR  rS  r:  rd  rU  rV  rW  rn  rC  rZ  rF  rB  r   )r%  r&  rG  r(  rh  rI  r+  r,  rK  r_  r/  rN  r1  r2  rp  r4  r5  rQ  rc  rj  rm  r:  rd  rU  r=  r?  rX  rC  )r   r   rg  )r   r  r   )r   r"  r  r!  kjr   js          r   test_jacobi_symbol_wikipediaz,TestIntegerBase.test_jacobi_symbol_wikipedia  s*      `  a  b  c  b  c  V  W  e  f  d  e  _  `  f  g  d  e  _  `  d  e  W  X  a  b  e  f" \\'' 	.EAr .1  Aq1-.	.r   c                 `    | j                  d      \  }| j                  t        |      d       y )Nr   0x10)r   r   hexr   s     r   test_hexzTestIntegerBase.test_hex  s&    mmD!R&)r   c                 :   | j                   j                  } |ddd      }| j                  |d        |ddd      }| j                  |d        |ddd      }| j                  |d        |ddd      }| j                  |d        |ddd      }| j                  |d       d	d
z  dz
  }ddz  }ddz  }d}| j                  | ||||             | j                  t        |ddd       | j                  t
        |ddd       | j                  t
        |ddd       y )Nrz   r{   r      r   ir   r-   r'   i   rC   r\   rl   r   s@   (ynpqB,f)Z*r}q:'z8%	[CUE2:r   r;   )r   _mult_modulo_bytesr   r   r   r   )r   modmultr   modulust1t2expects          r   test_mult_modulo_bytesz&TestIntegerBase.test_mult_modulo_bytes  s*   ,,11aBg&fa$g&a$g&fa$g&a$g&S&1*WW HR!9:+WaA>*gq!R8*gq!Q7r   N)8__name__
__module____qualname__r   r   r%   r+   r1   r9   r>   rM   rT   rY   r`   rc   re   rg   rj   ro   ru   rx   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#  rs  rw  r  r   r   r   r   r   .   s   7&-B-
)UI
G>M0	1
"
#"#+446>	7
36  ,,76
-
$
008;
0#2A)(< %77D
C-"	(< '	'!DF.4*8r   r   c                       e Zd Zd Zy)TestIntegerIntc                     t         | _        y r   )r   r   r
   s    r   r   zTestIntegerInt.setUp  s	    $r   Nr  r  r  r   r   r   r   r  r    s    %r   r  c                   $    e Zd Zd Zd Zd Zd Zy)testIntegerRandomc                 P   t        d      D ]@  }t        j                  d      }| j                  |dk         | j                  |dk\         B t        dd      D ]I  }t        j                  |      }| j                  |d|d	z
  z  k         | j                  |d|z  k\         K y )
Nr(   rH   )
exact_bits   rP   r^     r'   rC   )r   r   randomr   )r   _a
bits_values       r   test_random_exact_bitsz(testIntegerRandom.test_random_exact_bits  s    t 	'A$$2AQW%Q#X&	'
  h/ 	1J$$
;AQZ!^!445Q!Z-/0	1r   c                 ,   d}t        d      D ]5  }t        j                  d      }|xs |dk  }| j                  |dk\         7 | j	                  |       t        dd      D ]/  }t        j                  |      }| j                  |d	|z  k\         1 y )
NFr(   rH   )max_bitsr  rP   r^   r  r'   )r   r   r  r   r/   )r   flagr  r  r  s        r   test_random_max_bitsz&testIntegerRandom.test_random_max_bits  s    t 	%A$$a0A?1s7DQV$	% 	h/ 	1J$$j9AQ!Z-/0	1r   c                      G d dt               } |       }t        j                  d|      }| j                  |j                  d       y )Nc                       e Zd Zd Zd Zy)@testIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNGc                     d| _         y r   )counterr
   s    r   __init__zItestIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNG.__init__	  s	     r   c                 H    | xj                   |z  c_         t        d      |z  S r   )r  bchr)r   sizes     r   __call__zItestIntegerRandom.test_random_bits_custom_rng.<locals>.CustomRNG.__call__  s    $Aw~%r   N)r  r  r  r  r  r   r   r   	CustomRNGr    s    !&r   r  r   )r  randfuncrz   )objectr   r  r   r  )r   r  
custom_rngr  s       r   test_random_bits_custom_rngz-testIntegerRandom.test_random_bits_custom_rng  s?    	& 	& [
  BD++Q/r   c                 n   t         j                  }t        d      D ]+  } |dd      }| j                  d|cxk  xr dk  nc        - t        d      D ]+  } |dd      }| j                  d|cxk  xr dk  nc        - | j	                  t
        |ddd       | j	                  t
        |dd	       y )
N   rC   r   )min_inclusivemax_inclusive)r  max_exclusiver'   rB   )r  r  r  )r  r  )r   random_ranger   r/   r   r   )r   funcr   r  s       r   test_random_rangez#testIntegerRandom.test_random_range  s    ))s 	*A1B7AOOALbL)	* s 	)A1B7AOOAKRK(	) 	*d!1:; 	 	=*d!1Mr   N)r  r  r  r  r  r  r  r   r   r   r  r    s    
110Nr   r  c                 p   g }|t        t              z  }	 ddlm  G fddt              }|t        |      z  }	 ddlm  G fd	d
t              }|t        |      z  }|t        t              z  }|S # t
        t        f$ rh}t        j                  dk(  r t        j                  j                  d       n+t        j                  j                  dt        |      z         Y d }~d }~ww xY w# t
        t        f$ r5}t        j                  j                  dt        |      z         Y d }~d }~ww xY w)Nr   
IntegerGMPc                       e Zd Z fdZy)!get_tests.<locals>.TestIntegerGMPc                     | _         y r   r   )r   r  s    r   r   z'get_tests.<locals>.TestIntegerGMP.setUp,  s
    )r   Nr  r  s   r   TestIntegerGMPr  +  s    *r   r  win32zSkipping GMP tests on Windows
zSkipping GMP tests (%s)
IntegerCustomc                       e Zd Z fdZy)*get_tests.<locals>.TestIntegerCustomModexpc                     | _         y r   r   )r   r  s    r   r   z0get_tests.<locals>.TestIntegerCustomModexp.setUp:  s
    ,r   Nr  r  s   r   TestIntegerCustomModexpr  9  s    -r   r  z"Skipping custom modexp tests (%s)
)r   r  Crypto.Math._IntegerGMPr  r   ImportErrorOSErrorsysplatformstdoutwriter7   Crypto.Math._IntegerCustomr  r  )configtestsr  er  r  r  s        @@r   	get_testsr  $  s   E	_^,,ED6	*_ 	* 	00	J<	-o 	- 	!899 
_.//EL% ! D<<7"JJ>?JJ83q6AC	D ! J

>QGIIJs/   %A7 %C1 7C.AC))C.1D5 +D00D5__main__c                  <    t        j                  t                     S r   )unittest	TestSuiter  r   r   r   r   r   E  s    H&&y{3 r   suite)defaultTest)__doc__r  r  Crypto.SelfTest.st_commonr   Crypto.Util.py3compatCrypto.Math._IntegerNativer   TestCaser   r  r  r  r  r  mainr   r   r   <module>r     s}   D ! 
  5 # 4t
8h'' t
8n%_ %7N)) 7Nr  @ z3EHMMg& r   