ó Ï€öVc@sedZd„Zd„Zd„Zd„Zd„Zd„Zedkradd lZej ƒnd S( s/Common functionality shared by several modules.cCsÆ|dkrdS|dkr&| }n|d@d|}t|ƒddidd6dd6dd6dd 6d d 6d d 6d d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6|dS(ss Number of bits needed to represent a integer excluding any prefix 0 bits. As per definition from https://wiki.python.org/moin/BitManipulation and to match the behavior of the Python 3 API. Usage:: >>> bit_size(1023) 10 >>> bit_size(1024) 11 >>> bit_size(1025) 11 :param num: Integer value. If num is 0, returns 0. Only the absolute value of the number is considered. Therefore, signed integers will be abs(num) before the number's bit length is determined. :returns: Returns the number of bits in the integer. iis%xit0t1it2t3it4t5t6t7t8t9tatbtctdtetf(tlen(tnumthex_num((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pytbit_sizes    cCsZ|dkrtd|ƒ‚n|dkr/dSd}x|rU|d7}|dL}q8W|S(sM Returns the number of bits required to hold a specific long number. is%Only nonnegative numbers possible: %si(t ValueError(tnumbertbits((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pyt _bit_size=s    cCs>tt|ƒdƒ\}}|s-|dkr:|d7}n|S(s” Returns the number of bytes required to hold a specific long number. The number of bytes is rounded up. Usage:: >>> byte_size(1 << 1023) 128 >>> byte_size((1 << 1024) - 1) 128 >>> byte_size(1 << 1024) 129 :param number: An unsigned integer :returns: The number of bytes required to hold a specific long number. iii(tdivmodR(Rtquantatmod((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pyt byte_sizeQs c Cs»d}d}d}d}|}|}xU|dkr{||}|||}}||||}}||||}}q'W|dkr•||7}n|dkr®||7}n|||fS(s@Returns a tuple (r, i, j) such that r = gcd(a, b) = ia + jb ii(( R R txtytlxtlytoatobtq((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pyt extended_gcdls      cCsAt||ƒ\}}}|dkr=td||fƒ‚n|S(s`Returns x^-1 (mod n) >>> inverse(7, 4) 3 >>> (inverse(143, 4) * 143) % 4 1 is*x (%d) and n (%d) are not relatively prime(R#R(Rtntdividertinvt_((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pytinverse…s  c Cszd}d}x|D]}||9}qWxLt||ƒD];\}}||}t||ƒ}|||||}q7W|S(s…Chinese Remainder Theorem. Calculates x such that x = a[i] (mod m[i]) for each i. :param a_values: the a-values of the above equation :param modulo_values: the m-values of the above equation :returns: x such that x = a[i] (mod m[i]) for each i >>> crt([2, 3], [3, 5]) 8 >>> crt([2, 3, 2], [3, 5, 7]) 23 >>> crt([2, 3, 0], [7, 11, 15]) 135 ii(tzipR(( ta_valuest modulo_valuestmRtmodulotm_ita_itM_iR&((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pytcrt–s  t__main__iÿÿÿÿN( t__doc__RRRR#R(R1t__name__tdoctestttestmod(((s5/opt/awscli/lib/python2.7/site-packages/rsa/common.pyts )     #