
    Iiy                     $    S SK Jr   " S S5      rg)   )Pointc                       \ rS rSr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rSrg)Math   c                 &    [        XS-   S-  U5      $ )Nr   r   )pow)clsvalueprimes      8/venv/lib/python3.13/site-packages/ellipticcurve/math.pymodularSquareRootMath.modularSquareRoot   s    519*E22    c           	      f    U R                  U R                  U R                  U5      X#XE5      U5      $ )a  
Fast way to multily point and scalar in elliptic curves

:param p: First Point to mutiply
:param n: Scalar to mutiply
:param N: Order of the elliptic curve
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:param A: Coefficient of the first-order term of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point that represents the sum of First and Second Point
)_fromJacobian_jacobianMultiply_toJacobianr	   pnNAPs         r   multiplyMath.multiply
   s4       !!#//!"4aAA1
 	
r   c                     U R                  U R                  U R                  U5      U R                  U5      X45      U5      $ )ai  
Fast way to add two points in elliptic curves

:param p: First Point you want to add
:param q: Second Point you want to add
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:param A: Coefficient of the first-order term of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point that represents the sum of First and Second Point
)r   _jacobianAddr   )r	   r   qr   r   s        r   addMath.add   s=       S__Q/1CQJA
 	
r   c                 |    US:X  a  gSnSnX-  nUnUS:  a"  Xe-  nXCU-  -
  nXeU-  -
  n	UnUnU	nUnUS:  a  M"  X2-  $ )z
Extended Euclidean Algorithm. It's the 'division' in elliptic curves

:param x: Divisor
:param n: Mod for division
:return: Value representing the division
    r    )
r	   xr   lmhmlowhighrnmnws
             r   invMath.inv)   sn     6eAgA1fBaBDBCB Ag vr   c                 D    [        UR                  UR                  S5      $ )zu
Convert point to Jacobian coordinates

:param p: First Point you want to add
:return: Point in Jacobian coordinates
r   )r   r$   y)r	   r   s     r   r   Math._toJacobianE   s     QSS!##q!!r   c                     U R                  UR                  U5      nUR                  US-  -  U-  nUR                  US-  -  U-  n[	        XES5      $ )z
Convert point back from Jacobian coordinates

:param p: First Point you want to add
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point in default coordinates
      r"   )r,   zr$   r/   r   )r	   r   r   r4   r$   r/   s         r   r   Math._fromJacobianO   sO     GGACCOSS16\QSS16\QQ1~r   c                 p   UR                   S:X  a  [        SSS5      $ UR                   S-  U-  nSUR                  -  U-  U-  nSUR                  S-  -  X!R                  S-  -  -   U-  nUS-  SU-  -
  U-  nXeU-
  -  SUS-  -  -
  U-  nSUR                   -  UR                  -  U-  n	[        XxU	5      $ )a3  
Double a point in elliptic curves

:param p: Point you want to double
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:param A: Coefficient of the first-order term of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point that represents the sum of First and Second Point
r"   r2   r   r3      )r/   r   r$   r4   )
r	   r   r   r   ysqSMnxnynzs
             r   _jacobianDoubleMath._jacobianDouble^   s     33!8Aq>!ssax1nWs]a\AqL(A-dQUlar6lQ\)Q.!##gmq RR  r   c                 b   UR                   S:X  a  U$ UR                   S:X  a  U$ UR                  UR                  S-  -  U-  nUR                  UR                  S-  -  U-  nUR                   UR                  S-  -  U-  nUR                   UR                  S-  -  U-  nXV:X  a$  Xx:w  a  [        SSS5      $ U R	                  XU5      $ Xe-
  n	X-
  n
X-  U-  nX-  U-  nX[-  U-  nU
S-  U-
  SU-  -
  U-  nXU-
  -  X|-  -
  U-  nXR                  -  UR                  -  U-  n[        XU5      $ )a]  
Add two points in elliptic curves

:param p: First Point you want to add
:param q: Second Point you want to add
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:param A: Coefficient of the first-order term of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point that represents the sum of First and Second Point
r"   r2   r3   r   )r/   r$   r4   r   r>   )r	   r   r   r   r   U1U2S1S2HRH2H3U1H2r;   r<   r=   s                    r   r   Math._jacobianAddt   s=    33!8H33!8HccACC1Hn!ccACC1Hn!ccACC1Hn!ccACC1Hn!8xQ1~%&&qQ//GGeq[f\1}1frkAH$)"9o'1,##gmq RR  r   c                 f   UR                   S:X  d  US:X  a  [        SSS5      $ US:X  a  U$ US:  d  X#:  a  U R                  XU-  X4U5      $ US-  S:X  a&  U R                  U R                  XS-  X4U5      XE5      $ U R	                  U R                  U R                  XS-  X4U5      XE5      XU5      $ )a}  
Multily point and scalar in elliptic curves

:param p: First Point to mutiply
:param n: Scalar to mutiply
:param N: Order of the elliptic curve
:param P: Prime number in the module of the equation Y^2 = X^3 + A*X + B (mod p)
:param A: Coefficient of the first-order term of the equation Y^2 = X^3 + A*X + B (mod p)
:return: Point that represents the sum of First and Second Point
r"   r   r2   )r/   r   r   r>   r   r   s         r   r   Math._jacobianMultiply   s     33!8qAvAq>!6Hq5AF((E1;;Ea<&&%%aaq91   5 5aaq I1PRSXY
 	
r   r#   N)__name__
__module____qualname____firstlineno__classmethodr   r   r   r,   r   r   r>   r   r   __static_attributes__r#   r   r   r   r      s    3 3 
 
 
 
  6 " "   ! !* "! "!H 
 
r   r   N)pointr   r   r#   r   r   <module>rT      s    q
 q
r   