
    ,h,                     F    d dl Z d dlmZmZmZmZ d dlmZ  G d de      Zy)    N)
iter_rangebordbchrABC)Randomc                      e Zd Zej                  d        Zej                  d        Zej                  d        Zej                  d4d       Ze	ej                  d5d              Z
ej                  d        Zej                  d        Zej                  d        Zej                  d	        Zej                  d
        Zej                  d        Zej                  d        ZeZej                  d        Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zej                  d        Zej                  d6d       Zej                  d6d       Zej                  d        Zej                  d6d       Zej                  d        Zej                  d        Zej                  d        Zej                  d        Z ej                  d        Z!ej                  d        Z"ej                  d        Z#ej                  d        Z$ej                  d         Z%ej                  d!        Z&ej                  d"        Z'ej                  d#        Z(ej                  d$        Z)ej                  d%        Z*ej                  d&        Z+ej                  d'        Z,ej                  d(        Z-ej                  d)        Z.ej                  d*        Z/ej                  d+        Z0ej                  d,        Z1ej                  d-        Z2ej                  d.        Z3e	ej                  d/               Z4e	d0        Z5e6d1        Z7e6d2        Z8e	ej                  d3               Z9y)7IntegerBasec                      y N selfs    Z/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/Math/_IntegerBase.py__int__zIntegerBase.__int__)           c                      y r   r   r   s    r   __str__zIntegerBase.__str__-   r   r   c                      y r   r   r   s    r   __repr__zIntegerBase.__repr__1   r   r   c                      y r   r   )r   
block_size	byteorders      r   to_byteszIntegerBase.to_bytes5   r   r   c                      y r   r   )byte_stringr   s     r   
from_byteszIntegerBase.from_bytes9        	r   c                      y r   r   r   terms     r   __eq__zIntegerBase.__eq__?   r   r   c                      y r   r   r    s     r   __ne__zIntegerBase.__ne__C   r   r   c                      y r   r   r    s     r   __lt__zIntegerBase.__lt__G   r   r   c                      y r   r   r    s     r   __le__zIntegerBase.__le__K   r   r   c                      y r   r   r    s     r   __gt__zIntegerBase.__gt__O   r   r   c                      y r   r   r    s     r   __ge__zIntegerBase.__ge__S   r   r   c                      y r   r   r   s    r   __nonzero__zIntegerBase.__nonzero__W   r   r   c                      y r   r   r   s    r   is_negativezIntegerBase.is_negative\   r   r   c                      y r   r   r    s     r   __add__zIntegerBase.__add__a   r   r   c                      y r   r   r    s     r   __sub__zIntegerBase.__sub__e   r   r   c                      y r   r   )r   factors     r   __mul__zIntegerBase.__mul__i   r   r   c                      y r   r   r   divisors     r   __floordiv__zIntegerBase.__floordiv__m   r   r   c                      y r   r   r9   s     r   __mod__zIntegerBase.__mod__q   r   r   Nc                      y r   r   r   exponentmoduluss      r   inplace_powzIntegerBase.inplace_powu   r   r   c                      y r   r   r?   s      r   __pow__zIntegerBase.__pow__y   r   r   c                      y r   r   r   s    r   __abs__zIntegerBase.__abs__}   r   r   c                      y r   r   r   rA   s     r   sqrtzIntegerBase.sqrt   r   r   c                      y r   r   r    s     r   __iadd__zIntegerBase.__iadd__   r   r   c                      y r   r   r    s     r   __isub__zIntegerBase.__isub__   r   r   c                      y r   r   r    s     r   __imul__zIntegerBase.__imul__   r   r   c                      y r   r   r    s     r   __imod__zIntegerBase.__imod__   r   r   c                      y r   r   r    s     r   __and__zIntegerBase.__and__   r   r   c                      y r   r   r    s     r   __or__zIntegerBase.__or__   r   r   c                      y r   r   r   poss     r   
__rshift__zIntegerBase.__rshift__   r   r   c                      y r   r   rW   s     r   __irshift__zIntegerBase.__irshift__   r   r   c                      y r   r   rW   s     r   
__lshift__zIntegerBase.__lshift__   r   r   c                      y r   r   rW   s     r   __ilshift__zIntegerBase.__ilshift__   r   r   c                      y r   r   )r   ns     r   get_bitzIntegerBase.get_bit   r   r   c                      y r   r   r   s    r   is_oddzIntegerBase.is_odd   r   r   c                      y r   r   r   s    r   is_evenzIntegerBase.is_even   r   r   c                      y r   r   r   s    r   size_in_bitszIntegerBase.size_in_bits   r   r   c                      y r   r   r   s    r   size_in_byteszIntegerBase.size_in_bytes   r   r   c                      y r   r   r   s    r   is_perfect_squarezIntegerBase.is_perfect_square   r   r   c                      y r   r   )r   small_primes     r   fail_if_divisible_byz IntegerBase.fail_if_divisible_by   r   r   c                      y r   r   )r   abs      r   multiply_accumulatezIntegerBase.multiply_accumulate   r   r   c                      y r   r   )r   sources     r   setzIntegerBase.set   r   r   c                      y r   r   rH   s     r   inplace_inversezIntegerBase.inplace_inverse   r   r   c                      y r   r   rH   s     r   inversezIntegerBase.inverse   r   r   c                      y r   r   r    s     r   gcdzIntegerBase.gcd   r   r   c                      y r   r   r    s     r   lcmzIntegerBase.lcm   r   r   c                      y r   r   )rq   ra   s     r   jacobi_symbolzIntegerBase.jacobi_symbol   r   r   c                    | dv r| S |dz  dk(  r0t        | |dz   dz  |      }t        |d|      | k7  rt        d      |S d}|dz
  dz  }|dz  s|dz  }|dz  }|dz  s| j                  d      }	 t        ||dz
  dz  |      }|dk(  r|dz  }||dz
  k(  rnt        d      |}t        |||      }t        | ||      }	t        | |dz   dz  |      }
|	dk7  rtt        d|      D ]  }t        |	d|z  |      dk(  s n |k(  rt        d| |fz        t        |d||z
  dz
  z  |      }|}|dz  |z  }|	|dz  z  |z  }	|
|z  |z  }
|	dk7  rtt        |
d|      | k7  rt        d      |
S )	a  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   )ra   prootsqzeulermctrirr   s                r   _tonelli_shankszIntegerBase._tonelli_shanks   s   " ;Hq5A:q1q5Q,*D4A!# !=>>KUqLq5FA!GA q5 KKNAEa<+EzQA~9::1aL1aLAEa<#1f1% q!Q$?a' Av !JaQRV!STTAq1q519~q)AA1qAQTQAQ!A 1f q!Q<19::r   c                    |j                  dd      }|j                  dd      }|j                  dd      }|t        j                         j                  }||t	        d      ||t	        d      |xs |}|dz
  dz  dz   }d|dz  |z
  z
  }t         |d      d	         }||d|dz
  z  z  }|d|z  dz
  z  }| j                  t        |       ||dz
        z         S )
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   randomz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                    |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|r!t        dt        |j                        z         d||fvrt        d      ||dz
  }d||fv rt        d	      |t	        j
                         j                  }||z
  } | |      j                         }d
}d|cxk  r|k  s(n | j                  ||      }d|cxk  r
|k  s||z   S  &||z   S )a  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   rh   r   )	r   r   r   r   r   r   norm_maximumbits_needednorm_candidates	            r   random_rangezIntegerBase.random_rangeY  s6   & 

?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                      y)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term2rA   s      r   _mult_modulo_byteszIntegerBase._mult_modulo_bytes  s    & 	r   )r   big)r   r   ):__name__
__module____qualname__abcabstractmethodr   r   r   r   staticmethodr   r"   r$   r&   r(   r*   r,   r.   __bool__r0   r2   r4   r7   r;   r=   rB   rD   rF   rI   rK   rM   rO   rQ   rS   rU   rY   r[   r]   r_   rb   rd   rf   rh   rj   rl   ro   rs   rv   rx   rz   r|   r~   r   r   classmethodr   r   r   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   