HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/__pycache__/numbertheory.cpython-310.pyc
o

�h�E�@s8ddlmZddlZddlmZmZddlmZzeWne	y'e
ZYnwzddlmZm
Z
dZdZWn!eyWdZz
ddlm
Z
dZWneyTdZYnwYnwes\ergeeee
d	��f�ZddlZddlZddlZd	d
lmZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dd�Z#er�dd �Z$ner�d!d �Z$nej%d"kr�d#d �Z$nd$d �Z$zej&Z'Wn
e(y�d%d&�Z'Ynwd'd(�Z&d)d*�Z)d+d,�Z*d-d.�Z+d/d0�Z,d1d2�Z-d3d4�Z.d5d6�Z/d7d8�Z0d9d:�Z1d;d<�Z2d=d>�Z3d?d@�Z4gdA�Z5da6dS)B�)�divisionN)�
integer_types�PY2)�reduce)�powmod�mpzTF�r�)�
bit_lengthc@seZdZdZdS)�Errorz)Base class for exceptions in this module.N)�__name__�
__module__�__qualname__�__doc__�rr�E/usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/numbertheory.pyr/src@�eZdZdS)�JacobiErrorN�rr
rrrrrr5�rc@r)�SquareRootErrorNrrrrrr9rrc@r)�NegativeExponentErrorNrrrrrr=rrcCs,t�dt�|dkrtd|��t|||�S)z+Raise base to exponent, reducing by moduluszRFunction is unused in library code. If you use this code, change to pow() builtin.rz#Negative exponents (%d) not allowed)�warnings�warn�DeprecationWarningr�pow)�base�exponent�modulusrrr�modular_expAs��rcCs�|ddksJ�t|�dksJ�t|�t|�krK|ddkr=tdt|�d�D]}|||d|||||<q'|dd�}t|�t|�ks|S)z�Reduce poly by polymod, integer arithmetic modulo p.

    Polynomials are represented as lists of coefficients
    of increasing powers of x.���r	r�)�len�xrange)�poly�polymod�p�irrr�polynomial_reduce_modPs
(�r(cCsrt|�t|�ddg}tt|��D]}tt|��D]}|||||||||||<qqt|||�S)z�Polynomial multiplication modulo a polynomial over ints mod p.

    Polynomials are represented as lists of coefficients
    of increasing powers of x.r	r)r"r#r()�m1�m2r%r&�prodr'�jrrr�polynomial_multiply_modgs
*�r-cCs~||ksJ�|dkr
dgS|}|}|ddkr|}ndg}|dkr=|d}t||||�}|ddkr9t||||�}|dks!|S)z�Polynomial exponentiation modulo a polynomial over ints mod p.

    Polynomials are represented as lists of coefficients
    of increasing powers of x.rr	r!)r-)rrr%r&�G�k�srrr�polynomial_exp_mods�r1cCs�|dkstd��|ddkstd��||}|dkrdS|dkr"dS|d}}|ddkr<|d|d}}|ddks-|ddksN|ddksN|ddkrQd}nd	}|dkrY|S|d
dkrh|d
dkrh|}|t|||�S)z
Jacobi symbol�zn must be larger than 2r!r	z
n must be oddr��r �)r�jacobi)�a�n�a1�er0rrrr6�s*	
�$r6cCsvd|kr|ksJ�J�d|ksJ�|dkrdS|dkr |St||�}|dkr1td||f��|ddkrAt||dd|�S|dd	kryt||dd|�}|dkr_t||dd|�S||dksgJ�d|td||d	d|�|Str�td
|�}n|}td|�D].}t||d||�dkr�||df}td|dd||�}|dr�td��|dSq�td
��)z)Modular square root of a, mod p, p prime.rr	r!r z%d has no square root modulo %dr5r2r3�i���)rr	zp is not primezNo b found.)r6rrr�minr#r1�RuntimeError)r7r&�jac�d�	range_top�b�f�ffrrr�square_root_mod_prime�s:
$�rDcC�|dkrdSt|d|�S��Inverse of a mod m.rr )r�r7�mrrr�inverse_mod��rJcCs�|dkrdSt|�}t|�}td�td�}}|||}}|dkr<||}||||||||f\}}}}|dks"||S)rGrr	r�r7rI�lm�hm�low�high�rrrrrJ�s$�)r2r3cCrErF)rrHrrrrJrKcCsf|dkrdSd\}}|||}}|dkr/||}||||||||f\}}}}|dks||S)rGr)r	rr	rrLrrrrJs$�cCs|r|||}}|s|S)z1Greatest common divisor using Euclid's algorithm.r�r7rArrr�gcd2*s�rScG�:t|�dkrtt|�St|dd�rtt|d�S|dS)zRGreatest common divisor.

    Usage: gcd([ 2, 4, 6 ])
    or:    gcd(2, 4, 6)
    r	r�__iter__)r"rrS�hasattr�r7rrr�gcd1�

rXcCs||t||�S)z&Least common multiple of two integers.)rXrRrrr�lcm2?srZcGrT)zPLeast common multiple.

    Usage: lcm([ 3, 4, 5 ])
    or:    lcm(3, 4, 5)
    r	rrU)r"rrZrVrWrrr�lcmErYr[cCsNt|t�sJ�|dkr
gSg}tD]6}||krn/t||�\}}|dkrGd}||kr@|}t||�\}}|dkr8n|d}||ks*|�||f�q|tdkr�t|�r[|�|df�|Std}	|d}t||�\}}||krpn*|dkr�d}|}||kr�t||�\}}|dkr�n
|}|d}||ks||�||f�q`|dkr�|�|df�|S)z2Decompose n into a list of (prime,exponent) pairs.r!rr	r )�
isinstancer�smallprimes�divmod�append�is_prime)r8�resultr?�qrQ�countrrr�
factorizationSsX�����rdcCs�t�dt�t|t�s
J�|dkrdSd}t|�}|D]#}|d}|dkr6||d|d|dd}q||dd}q|S)z'Return the Euler totient function of n.�{Function is unused by library code. If you use this code, please open an issue in https://github.com/tlsfuzzer/python-ecdsar2r	r)rrrr\rrd)r8rarCrBr:rrr�phi�s�"rfcCst�dt�tt|��S)z�Return Carmichael function of n.

    Carmichael(n) is the smallest integer x such that
    m**x = 1 mod n for all m relatively prime to n.
    re)rrr�carmichael_of_factorizedrd)r8rrr�
carmichael�s
�rhcCsRt�dt�t|�dkrdSt|d�}tdt|��D]}t|t||��}q|S)zlReturn the Carmichael function of a number that is
    represented as a list of (prime,exponent) pairs.
    rer	r)rrrr"�carmichael_of_ppowerr#r[)�f_listrar'rrrrg�s�rgcCsDt�dt�|\}}|dkr|dkrd|dS|d||dS)z:Carmichael function of the given power of the given prime.rer!r	)rrr)�ppr&r7rrrri�s�ricCsZt�dt�|dkrdSt||�dksJ�|}d}|dkr+|||}|d}|dks|S)z8Return the order of x in the multiplicative group mod m.rer	r)rrrrX)�xrI�zrarrr�	order_mod�s�
�rncCsLt�dt�	t||�}|dkr	|S|}	t||�\}}|dkr"n|}qq)z5Return the largest factor of a relatively prime to b.rer	r)rrrrXr^)r7rAr?rbrQrrr�largest_factor_relatively_prime�s"�
���rocCst�dt�t|t||��S)z}Return the order of x in the multiplicative group mod m',
    where m' is the largest factor of m relatively prime to x.
    re)rrrrnro)rlrIrrr�kinda_order_mods
�rpcCsdda|tdkr|tvrdSdSt|d�dkrdSd}dt|�}d|kr,d	ks/J�J�d
D]\}}||kr;n|}q1d}|d}|ddkrX|d}|d}|ddksJt|�D]S}t�t�}t|||�}	|	dkr�|	|dkr�d}
|
|dkr�|	|dkr�t|	d|�}	|	dkr�|dadS|
d}
|
|dkr�|	|dks�|	|dkr�|dadSq\dS)a@Return True if x is prime, False otherwise.

    We use the Miller-Rabin test, as given in Menezes et al. p. 138.
    This test is not exact: there are composite values n for which
    it returns True.

    In testing the odd numbers from 10000001 to 19999999,
    about 66 composites got past the first test,
    5 got past the second test, and none got past the third.
    Since factors of 2, 3, 5, 7, and 11 were detected during
    preliminary screening, the number of numbers tested by
    Miller-Rabin was (19999999 - 10000001)*(2/3)*(4/5)*(6/7)
    = 4.57 million.
    rr TFi	r	�(�i@))�d�)��)���)��)i,�	)i^r3)i�r4)i��)i&r;)i�r5)iRr2)ir!r!)�miller_rabin_test_countr]rXr
r#�random�choicer)r8�t�n_bitsr/�ttr0rQr'r7�yr,rrrr`sJ�
��r`cCs4|dkrdS|ddB}t|�s|d}t|�r|S)z9Return the smallest prime larger than the starting value.r!r	)r`)�starting_valuerarrr�
next_primels�r�)�r!r2r;r4rr�
������%�)�+�/�5�;�=�C�G�I�O�S�Y�a�e�g�k�m�q���������������������������������iii
iiiii%i3i7i9i=iKiQi[i]iaigioiui{ii�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i	iii#i-i3i9i;iAiKiQiWiYi_ieiiikiwi�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�iiiii)i+i5i7i;i=iGiUiYi[i_imiqisiwi�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�ii	iiii%i'i-i?iCiEiIiOiUi]iciiii�i�i�i�i�i�i�i�i�i�i�)7�
__future__r�sys�sixrr�	six.movesrr#�	NameError�range�gmpy2rr�GMPY2�GMPY�ImportError�gmpy�tuple�type�mathrr~�utilr
�	Exceptionrrrrrr(r-r1r6rDrJ�version_inforXrS�AttributeErrorrZr[rdrfrhrgrirnrorpr`r�r]r}rrrr�<module>s�����
  1




�	8OM