
    i,                     F    S SK r S SKJrJrJrJr  S SKJr   " S S\5      rg)    N)
iter_rangebordbchrABC)Randomc                      \ rS rSr\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S6S j5       r	\
\R
                  S7S j5       5       r\R
                  S 5       r\R
                  S 5       r\R
                  S	 5       r\R
                  S
 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r\R
                  S8S j5       r\R
                  S8S j5       r\R
                  S 5       r\R
                  S8S j5       r\R
                  S 5       r\R
                  S 5       r\R
                  S 5       r \R
                  S 5       r!\R
                  S 5       r"\R
                  S 5       r#\R
                  S 5       r$\R
                  S  5       r%\R
                  S! 5       r&\R
                  S" 5       r'\R
                  S# 5       r(\R
                  S$ 5       r)\R
                  S% 5       r*\R
                  S& 5       r+\R
                  S' 5       r,\R
                  S( 5       r-\R
                  S) 5       r.\R
                  S* 5       r/\R
                  S+ 5       r0\R
                  S, 5       r1\R
                  S- 5       r2\R
                  S. 5       r3\R
                  S/ 5       r4\
\R
                  S0 5       5       r5\
S1 5       r6\7S2 5       r8\7S3 5       r9\
\R
                  S4 5       5       r:S5r;g)9IntegerBase&   c                     g N selfs    S/var/www/html/trading/venv/lib/python3.13/site-packages/Crypto/Math/_IntegerBase.py__int__IntegerBase.__int__)           c                     g r   r   r   s    r   __str__IntegerBase.__str__-   r   r   c                     g r   r   r   s    r   __repr__IntegerBase.__repr__1   r   r   c                     g r   r   )r   
block_size	byteorders      r   to_bytesIntegerBase.to_bytes5   r   r   c                     g r   r   )byte_stringr   s     r   
from_bytesIntegerBase.from_bytes9        	r   c                     g r   r   r   terms     r   __eq__IntegerBase.__eq__?   r   r   c                     g r   r   r&   s     r   __ne__IntegerBase.__ne__C   r   r   c                     g r   r   r&   s     r   __lt__IntegerBase.__lt__G   r   r   c                     g r   r   r&   s     r   __le__IntegerBase.__le__K   r   r   c                     g r   r   r&   s     r   __gt__IntegerBase.__gt__O   r   r   c                     g r   r   r&   s     r   __ge__IntegerBase.__ge__S   r   r   c                     g r   r   r   s    r   __nonzero__IntegerBase.__nonzero__W   r   r   c                     g r   r   r   s    r   is_negativeIntegerBase.is_negative\   r   r   c                     g r   r   r&   s     r   __add__IntegerBase.__add__a   r   r   c                     g r   r   r&   s     r   __sub__IntegerBase.__sub__e   r   r   c                     g r   r   )r   factors     r   __mul__IntegerBase.__mul__i   r   r   c                     g r   r   r   divisors     r   __floordiv__IntegerBase.__floordiv__m   r   r   c                     g r   r   rJ   s     r   __mod__IntegerBase.__mod__q   r   r   Nc                     g r   r   r   exponentmoduluss      r   inplace_powIntegerBase.inplace_powu   r   r   c                     g r   r   rR   s      r   __pow__IntegerBase.__pow__y   r   r   c                     g r   r   r   s    r   __abs__IntegerBase.__abs__}   r   r   c                     g r   r   r   rT   s     r   sqrtIntegerBase.sqrt   r   r   c                     g r   r   r&   s     r   __iadd__IntegerBase.__iadd__   r   r   c                     g r   r   r&   s     r   __isub__IntegerBase.__isub__   r   r   c                     g r   r   r&   s     r   __imul__IntegerBase.__imul__   r   r   c                     g r   r   r&   s     r   __imod__IntegerBase.__imod__   r   r   c                     g r   r   r&   s     r   __and__IntegerBase.__and__   r   r   c                     g r   r   r&   s     r   __or__IntegerBase.__or__   r   r   c                     g r   r   r   poss     r   
__rshift__IntegerBase.__rshift__   r   r   c                     g r   r   rt   s     r   __irshift__IntegerBase.__irshift__   r   r   c                     g r   r   rt   s     r   
__lshift__IntegerBase.__lshift__   r   r   c                     g r   r   rt   s     r   __ilshift__IntegerBase.__ilshift__   r   r   c                     g r   r   )r   ns     r   get_bitIntegerBase.get_bit   r   r   c                     g r   r   r   s    r   is_oddIntegerBase.is_odd   r   r   c                     g r   r   r   s    r   is_evenIntegerBase.is_even   r   r   c                     g r   r   r   s    r   size_in_bitsIntegerBase.size_in_bits   r   r   c                     g r   r   r   s    r   size_in_bytesIntegerBase.size_in_bytes   r   r   c                     g r   r   r   s    r   is_perfect_squareIntegerBase.is_perfect_square   r   r   c                     g r   r   )r   small_primes     r   fail_if_divisible_by IntegerBase.fail_if_divisible_by   r   r   c                     g r   r   )r   abs      r   multiply_accumulateIntegerBase.multiply_accumulate   r   r   c                     g r   r   )r   sources     r   setIntegerBase.set   r   r   c                     g r   r   r^   s     r   inplace_inverseIntegerBase.inplace_inverse   r   r   c                     g r   r   r^   s     r   inverseIntegerBase.inverse   r   r   c                     g r   r   r&   s     r   gcdIntegerBase.gcd   r   r   c                     g r   r   r&   s     r   lcmIntegerBase.lcm   r   r   c                     g r   r   )r   r   s     r   jacobi_symbolIntegerBase.jacobi_symbol   r$   r   c                    U S;   a  U $ US-  S:X  a0  [        XS-   S-  U5      n[        USU5      U :w  a  [        S5      eU$ SnUS-
  S-  nUS-  (       d  US-  nUS-  nUS-  (       d  M  U R                  S5      n [        XQS-
  S-  U5      nUS:X  a  US-  nM   XaS-
  :X  a  O[        S5      eUn[        XTU5      n[        XU5      n	[        XS-   S-  U5      n
U	S:w  av  [        SU5       H  n[        U	SU-  U5      S:X  d  M    O   WU:X  a  [        SX4-  5      e[        USX{-
  S-
  -  U5      nUnUS-  U-  nXS-  -  U-  n	X-  U-  n
U	S:w  a  Mv  [        U
SU5      U :w  a  [        S5      eU
$ )	an  Tonelli-shanks algorithm for computing the square root
of n modulo a prime p.

n must be in the range [0..p-1].
p must be at least even.

The return value r is the square root of modulo p. If non-zero,
another solution will also exist (p-r).

Note we cannot assume that p is really a prime: if it's not,
we can either raise an exception or return the correct value.
)r            r      zCannot compute square rootr   z'Cannot compute square root of %d mod %d)pow
ValueError	__class__r   )r   prootsqzeulermctrir   s                r   _tonelli_shanksIntegerBase._tonelli_shanks   s   " ;Hq5A:qq5Q,*D4A!# !=>>KUqLq5FA!GA q55 KKNEa<+EzQA~9::aLaLEa<#1f1%q!Q$?a' & Av !JaV!STTAq1519~q)AA1qATQA!A 1f q!Q<19::r   c                    UR                  SS5      nUR                  SS5      nUR                  SS5      nUc  [        R                  " 5       R                  nUc  Uc  [	        S5      eUb  Ub  [	        S5      eU=(       d    UnUS-
  S-  S-   nSUS-  U-
  -
  n[        U" S5      S	   5      nUb  USUS-
  -  -  nUSU-  S-
  -  nU R                  [        U5      U" US-
  5      -   5      $ )
a  Generate a random natural integer of a certain size.

:Keywords:
  exact_bits : positive integer
    The length in bits of the resulting random Integer number.
    The number is guaranteed to fulfil the relation:

        2^bits > result >= 2^(bits - 1)

  max_bits : positive integer
    The maximum length in bits of the resulting random Integer number.
    The number is guaranteed to fulfil the relation:

        2^bits > result >=0

  randfunc : callable
    A function that returns a random byte string. The length of the
    byte string is passed as parameter. Optional.
    If not provided (or ``None``), randomness is read from the system RNG.

:Return: a Integer object

exact_bitsNmax_bitsrandfuncz3Either 'exact_bits' or 'max_bits' must be specifiedz2'exact_bits' and 'max_bits' are mutually exclusiver      r   )popr   newreadr   r   r"   r   )	clskwargsr   r   r   bitsbytes_neededsignificant_bits_msbmsbs	            r   randomIntegerBase.random)  s   2 ZZd3
::j$/::j$/zz|((H("2RSS!h&:QRR%Xa1, L1$4t$;<8A;q>"!1-122C))Q..~~d3i(<!3C*DDEEr   c                 (   UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nU(       a!  [        S[        UR                  5      -   5      eSX44;  a  [        S5      eUb  US-
  nSX#4;   a  [        S	5      eUc  [        R
                  " 5       R                  nX2-
  nU " U5      R                  5       nS
nSUs=::  a  U::  d(  O  U R                  UUS9nSUs=::  a  U::  d  M   X-   $   N&X-   $ )a2  Generate a random integer within a given internal.

:Keywords:
  min_inclusive : integer
    The lower end of the interval (inclusive).
  max_inclusive : integer
    The higher end of the interval (inclusive).
  max_exclusive : integer
    The higher end of the interval (exclusive).
  randfunc : callable
    A function that returns a random byte string. The length of the
    byte string is passed as parameter. Optional.
    If not provided (or ``None``), randomness is read from the system RNG.
:Returns:
    An Integer randomly taken in the given interval.
min_inclusiveNmax_inclusivemax_exclusiver   zUnknown keywords: z8max_inclusive and max_exclusive cannot be both specifiedr   z(Missing keyword to identify the intervalr   )r   r   )	r   r   strkeysr   r   r   r   r   )	r   r   r   r   r   r   norm_maximumbits_needednorm_candidates	            r   random_rangeIntegerBase.random_rangeY  s,   & 

?D9

?D9

?D9::j$/1C4DDEE55 & ' '$)A-MM11GHHzz|((H$4,'446~55 ZZ-8-5 ( &N ~55
 -- 6
 --r   c                     g)a  Multiply two integers, take the modulo, and encode as big endian.
This specialized method is used for RSA decryption.

Args:
  term1 : integer
    The first term of the multiplication, non-negative.
  term2 : integer
    The second term of the multiplication, non-negative.
  modulus: integer
    The modulus, a positive odd number.
:Returns:
    A byte string, with the result of the modular multiplication
    encoded in big endian mode.
    It is as long as the modulus would be, with zero padding
    on the left if needed.
Nr   )term1term2rT   s      r   _mult_modulo_bytesIntegerBase._mult_modulo_bytes  s    & 	r   r   )r   big)r   r   )<__name__
__module____qualname____firstlineno__abcabstractmethodr   r   r   r   staticmethodr"   r(   r+   r.   r1   r4   r7   r:   __bool__r=   r@   rC   rG   rL   rO   rU   rX   r[   r_   rb   re   rh   rk   rn   rq   rv   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   __static_attributes__r   r   r   r	   r	   &   s$    	  	  	  	     	  	  	  	  	  	  	 H  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	     > >@ -F -F^ -. -.^   r   r	   )	r   Crypto.Util.py3compatr   r   r   r   Cryptor   r	   r   r   r   <module>r      s!   >  = = v# vr   