HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/rsa/__pycache__/randnum.cpython-38.pyc
U

�0�[S
�@sLdZddlZddlmZmZddlmZdd�Zdd�Zd	d
�Z	dd�Z
dS)
z(Functions for generating random numbers.�N)�common�	transform)�bytecCsJt|d�\}}t�|�}|dkrFtt�d��}|d|L}t|�|}|S)z�Reads 'nbits' random bits.

    If nbits isn't a whole number of bytes, an extra byte will be appended with
    only the lower bits set.
    �r�)�divmod�os�urandom�ordr)�nbits�nbytesZrbits�
randomdataZrandomvalue�r�-/usr/lib/python3/dist-packages/rsa/randnum.py�read_random_bitss
rcCs&t|�}t�|�}|d|d>O}|S)z8Reads a random integer of approximately nbits bits.
    r)rrZ	bytes2int)rr
�valuerrr�read_random_int0s
rcCst|�}|dBS)zhReads a random odd integer of approximately nbits bits.

    >>> read_random_odd_int(512) & 1
    1
    r)r)rrrrr�read_random_odd_int>srcCsFt�|�}d}t|�}||kr qB|ddkr8|r8|d8}|d7}q|S)z�Returns a random integer x with 1 <= x <= maxvalue

    May take a very long time in specific situations. If maxvalue needs N bits
    to store, the closer maxvalue is to (2 ** N) - 1, the faster this function
    is.
    r�
r)r�bit_sizer)ZmaxvaluerZtriesrrrr�randintKs

r)�__doc__rZrsarrZrsa._compatrrrrrrrrr�<module>s