o
    Y¨Êhˆ  ã                   @   sf   d Z g d¢ZddlZejd dkrejd dkrddlT dd„ Zd	d
„ Zdd„ Zdd„ Zddd„Z	dS )z$Id$)Ú
ceil_shiftÚceil_divÚ	floor_divÚ
exact_log2Ú	exact_divé    Né   é   )Ú*c                 C   sl   t | tƒr
t |tƒstdt| ƒjt|ƒjf ƒ‚| dkr |dks"J ‚d|> d }| |@ r2| |? d S | |? S )zÏReturn ceil(n / 2**b) without performing any floating-point or division operations.

    This is done by right-shifting n by b bits and incrementing the result by 1
    if any '1' bits were shifted out.
    ú&unsupported operand type(s): %r and %rr   r   )Ú
isinstanceÚintÚ	TypeErrorÚtypeÚ__name__)ÚnÚbÚmask© r   úI/var/www/html/env/lib/python3.10/site-packages/Crypto/Util/_number_new.pyr   "   s   r   c                 C   sN   t | tƒr
t |tƒstdt| ƒjt|ƒjf ƒ‚t| |ƒ\}}|r%|d S |S )zDReturn ceil(a / b) without performing any floating-point operations.r
   r   ©r   r   r   r   r   Údivmod©Úar   ÚqÚrr   r   r   r   2   s   r   c                 C   sB   t | tƒr
t |tƒstdt| ƒjt|ƒjf ƒ‚t| |ƒ\}}|S )Nr
   r   r   r   r   r   r   >   s   r   c                 C   sŽ   t | tƒstdt| ƒjf ƒ‚t| ƒ}|dkrtdƒ‚d}|dkr9|d@ r-|dkr-tdƒ‚|d7 }|dL }|dks!|d8 }| d|> ksEJ ‚|S )z~Find and return an integer i >= 0 such that num == 2**i.

    If no such integer exists, this function raises ValueError.
    zunsupported operand type: %rr   z/cannot compute logarithm of non-positive numberr   úNo solution could be found)r   r   r   r   r   Ú
ValueError)Únumr   Úir   r   r   r   E   s   
ür   Fc                 C   sˆ   t | tƒr
t |tƒstdt| ƒjt|ƒjf ƒ‚|dkr+|r+d}| || kr*tdƒ‚nt| |ƒ\}}|dkr:tdƒ‚| || ksBJ ‚|S )a  Find and return an integer n such that p == n * d

    If no such integer exists, this function raises ValueError.

    Both operands must be integers.

    If the second operand is zero, this function will raise ZeroDivisionError
    unless allow_divzero is true (default: False).
    r
   r   r   )r   r   r   r   r   r   r   )ÚpÚdÚallow_divzeror   r   r   r   r   r   ]   s   ÿr   )F)
Ú__revision__Ú__all__ÚsysÚversion_infoÚCrypto.Util.py21compatr   r   r   r   r   r   r   r   r   Ú<module>   s   