ff*FddlmZddlmZmZmZmZGddeZdS)) IntegerBase) long_to_bytes bytes_to_longinverseGCDcfeZdZdZdZdZdZdZdZdZ d6d Z e d7d Z d Z d ZdZdZdZdZdZeZdZdZdZdZdZdZd8dZd8dZdZd8dZdZdZ d Z!d!Z"d"Z#d#Z$d$Z%d%Z&d&Z'd'Z(d(Z)d)Z*d*Z+d+Z,d,Z-d-Z.d.Z/d/Z0d0Z1d1Z2d2Z3d3Z4d4Z5e6d5Z7dS)9 IntegerNativez3A class to model a natural integer (including zero)ct|trtd |j|_dS#t$r ||_YdSwxYw)Nz-A floating point type is not a natural number) isinstancefloat ValueError_valueAttributeError)selfvalues |/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Math/_IntegerNative.py__init__zIntegerNative.__init__'s^ eU # # NLMM M ,DKKK   DKKKK s 4A A c|jSNrrs r__int__zIntegerNative.__int__0s {c:tt|Sr)strintrs r__str__zIntegerNative.__str__3s3t99~~rc&dt|zS)Nz Integer(%s))rrs r__repr__zIntegerNative.__repr__6ss4yy((rc*t|jSr)hexrrs r__hex__zIntegerNative.__hex__:4;rc*t|jSrrrrs r __index__zIntegerNative.__index__>r$rrbigcZ|jdkrtdt|j|}t||cxkrdkrnntd|dkrnH|dkr3t |}|t |}ntd|S)Nr.Conversion only valid for non-negative numberszValue too large to encoder(littleIncorrect byteorder)rrrlen bytearrayreversebytes)r block_size byteorderresults rto_byteszIntegerNative.to_bytesAs ;??MNN Nt{J77 v;; ' ' ' 'a ' ' ' ' '899 9     ( " "v&&F NN   6]]FF233 3 rc|dkrn9|dkr$t|}|ntd|t|S)Nr(r+r,)r.r/rr)cls byte_stringr2s r from_byteszIntegerNative.from_bytesQsd     ( " "#K00K    ! ! ! !233 3s=--...rc:|dS|jt|kS)NFrrrterms r__eq__zIntegerNative.__eq__]s <5{c$ii''rc.|| Sr)r=r;s r__ne__zIntegerNative.__ne__b;;t$$$$rc2|jt|kSrr:r;s r__lt__zIntegerNative.__lt__es{SYY&&rcV||p||Sr)rBr=r;s r__le__zIntegerNative.__le__hs%{{4  5DKK$5$55rc.|| Sr)rDr;s r__gt__zIntegerNative.__gt__kr@rc.|| Sr)rBr;s r__ge__zIntegerNative.__ge__nr@rc|jdkSNrrrs r __nonzero__zIntegerNative.__nonzero__qs{arc|jdkSrJrrs r is_negativezIntegerNative.is_negativeus{Qrc ||jt|zS#ttt f$r t cYSwxYwr __class__rrrr TypeErrorNotImplementedr;s r__add__zIntegerNative.__add__yT ">>$+D "9:: :NI6 " " "! ! ! ! "),A  A c ||jt|z S#ttt f$r t cYSwxYwrrOr;s r__sub__zIntegerNative.__sub__rTrUc ||jt|zS#ttt f$r t cYSwxYwrrO)rfactors r__mul__zIntegerNative.__mul__sT ">>$+F ";<< <NI6 " " "! ! ! ! "rUcV||jt|zSrrPrr)rdivisors r __floordiv__zIntegerNative.__floordiv__s!~~dkS\\9:::rct|}|dkrtd||j|zS)NrModulus must be positive)rrrPr)rr] divisor_values r__mod__zIntegerNative.__mod__s@G 1  788 8~~dkM9:::rNct|}|dkrtd|:t|}|dkrtd|dkrtdnd}t|j|||_|S)NrzExponent must not be negativer`zModulus cannot be zero)rrZeroDivisionErrorpowr)rexponentmodulus exp_value mod_values r inplace_powzIntegerNative.inplace_powsMM q==<== =  G I1}} !;<<<A~~'(@AAAI$+y)<<  rcX||}|||Sr)rPrj)rrfrgr3s r__pow__zIntegerNative.__pow__s)%%!!(G444rc*t|jSr)absrrs r__abs__zIntegerNative.__abs__r$rc|j}|;|dkrtd|}|dzdz}||kr|}|||zzdz}||k|}n.|dkrtd|||z|}||S)NrzSquare root of negative valuerr`)rr_tonelli_shanksrP)rrgrxyr3s rsqrtzIntegerNative.sqrts  ?qyy !@AAAAQ1 Aa%%!^)a%%FF!|| !;<<<))$.'BBF~~f%%%rc@|xjt|z c_|Srr:r;s r__iadd__zIntegerNative.__iadd__ s4yy  rc@|xjt|zc_|Srr:r;s r__isub__zIntegerNative.__isub__rxrc@|xjt|zc_|Srr:r;s r__imul__zIntegerNative.__imul__rxrct|}|dkrtd|dkrtd|xj|zc_|S)NrzDivision by zeror`)rrdrr)rr<rgs r__imod__zIntegerNative.__imod__sRd)) a<<#$677 7 Q;;788 8 w  rcV||jt|zSrr\r;s r__and__zIntegerNative.__and__!~~dkCII5666rcV||jt|zSrr\r;s r__or__zIntegerNative.__or__rrc ||jt|z S#t$r|jdkrYdSYdSwxYwNr)rPrr OverflowErrorrposs r __rshift__zIntegerNative.__rshift__s\ >>$+S"9:: :   {aqqrr  s),AAc |xjt|zc_n#t$r|jdkrYdSYdSwxYw|Sr)rrrrs r __irshift__zIntegerNative.__irshift__s\  KKCHH $KKK   {aqqrr    s  <<c ||jt|zS#t$rt dwxYwNzIncorrect shift count)rPrrrrrs r __lshift__zIntegerNative.__lshift__sP 6>>$+S"9:: : 6 6 6455 5 6s ),Ac~ |xjt|zc_n#t$rtdwxYw|Sr)rrrrrs r __ilshift__zIntegerNative.__ilshift__sN 6 KKCHH $KKK 6 6 6455 5 6 s :c"|jdkrtd |j|jz dz}|jdkrtdn2#t$r%|j|z dz}|dkrtdYnwxYwn#t$rd}YnwxYw|S)Nrz)no bit representation for negative valuesrznegative bit count)rrrr)rnr3s rget_bitzIntegerNative.get_bits ;??HII I  ;+1Q68a<<$%9::: ! ; ; ;+*a/q55$%9:::5 ;   FFF  s/,A A= ,A96A=8A99A== B  B c|jdzdkS)Nrrrs ris_oddzIntegerNative.is_odd  aA%%rc|jdzdkS)Nrrrrs ris_evenzIntegerNative.is_evenrrc|jdkrtd|jdkrdS|jS)Nrr*r)rr bit_lengthrs r size_in_bitszIntegerNative.size_in_bitssB ;??MNN N ;!  1{%%'''rc<|dz dzdzS)Nr)rrs r size_in_byteszIntegerNative.size_in_bytess#!!##a'A-11rc|jdkrdS|jdvrdS|jdz}|dz}||jkr ||jzd|zz}|dz}||jk |j|dzkS)NrF)rrTrqr)rrssquare_xs ris_perfect_squarezIntegerNative.is_perfect_square s ;??5 ;& 4 K1 6$$DK'QU3AAvH$${a1f$$rcZ|jt|zdkrtddS)NrzValue is composite)rrr)r small_primes rfail_if_divisible_byz"IntegerNative.fail_if_divisible_by/s3 K#k** *q 0 0122 2 1 0rc`|xjt|t|zz c_|Srr:)rabs rmultiply_accumulatez!IntegerNative.multiply_accumulate3s' s1vvA&  rc.t||_dSrr&)rsources rsetzIntegerNative.set7s&kk rcTt|jt||_|Sr)rrr)rrgs rinplace_inversezIntegerNative.inplace_inverse:s dk3w<<88  rcZ||}|||Sr)rPr)rrgr3s rrzIntegerNative.inverse>s,%%w''' rc |tt|jtt |Sr)rPrrnrrr;s rgcdzIntegerNative.gcdCs4~~c#dk"2"2CD NNCCDDDrct|}|jdks|dkr|dS|t|j|z||jzSrJ)rrrPrnrr;s rlcmzIntegerNative.lcmFsg4yy ;!  tqyy>>!$$ $~~c4;#5$((4..:O"OPPQQQrct|}t|}|dkrtd|dzdkrtd||z}|dks|dkrdS|dkrdSd}|}|dzdkr|dz}|dz }|dzdk|dzdkrd}n |dzdvrd}nd}|dzd kr |dzd kr| }||z}|t||zS) Nrzn must be a positive integerrz#n must be odd for the Jacobi symbolr)rr)rrr jacobi_symbol)rrea1sn1s rrzIntegerNative.jacobi_symbolLs& FF FF 66;<< < Ea<<BCC C E 66Q!VV1 661  Av!mm 1HB FAAv!mm Ea<<AA Uf__AAA q5A::"q&A++A V=..r26666r)rr()r(r)8__name__ __module__ __qualname____doc__rrrr r#r'r4 classmethodr8r=r?rBrDrFrHrK__bool__rMrSrWrZr^rbrjrlrorurwrzr|r~rrrrrrrrrrrrrrrrrrr staticmethodrrrr r $s5==   )))       ///[/((( %%%'''666%%%%%%   H""" """ """ ;;;;;;  5555   &&&&*777777666 "&&&&&&(((222 % % %333""" EEERRR %7%7\%7%7%7rr N) _IntegerBaserCrypto.Util.numberrrrrr rrrrs{>&%%%%%IIIIIIIIIIIIN7N7N7N7N7KN7N7N7N7N7r