o 0¦i|Qã@sàdZddlZddlZddlZgd¢ZeefZdd„ZdQdd„Z dRd d „Z d d „Z d d„Z e  dd¡Ze  dd¡Zdd„Zdd„ZdZdZdZdZdZiaiadd„ZdSdd„Zdd„Zejd d!�e_dSd"d#„Zejd ed$�e_d%d&„Zejd'd!�e_dTd(d)„Zejd'd*d$�e_d+d,„Z dTd-d.„Z!da"da#d/Z$d0Z%dUd1d2„Z&ddddd3œd4d5„Z'ddd6d7œd8d9„Z(d:Z)da*da+da,dTd;d<„Z-d=d>„Z.d?Z/e/d@dAZ0dBdC„Z1dDdE„Z2dFdG„Z3dHdI„Z4dJdK„Z5dLdM„Z6dNdO„Z7e8dPkrîe6ƒdSdS)VzDBase16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodingséN)ÚencodeÚdecodeÚ encodebytesÚ decodebytesÚ b64encodeÚ b64decodeÚ b32encodeÚ b32decodeÚ b32hexencodeÚ b32hexdecodeÚ b16encodeÚ b16decodeÚ b85encodeÚ b85decodeÚ a85encodeÚ a85decodeÚstandard_b64encodeÚstandard_b64decodeÚurlsafe_b64encodeÚurlsafe_b64decodecCslt|tƒrz| d¡WStytdƒ‚wt|tƒr|Szt|ƒ ¡WSty5td|j j ƒd‚w)NÚasciiz4string argument should contain only ASCII charactersz>argument should be a bytes-like object or ASCII string, not %r) Ú isinstanceÚstrrÚUnicodeEncodeErrorÚ ValueErrorÚ bytes_typesÚ memoryviewÚtobytesÚ TypeErrorÚ __class__Ú__name__©Ús©r#ú-/opt/alt/python310/lib64/python3.10/base64.pyÚ_bytes_from_decode_data"s"   ÿ  ÿÿÿr%cCs,tj|dd�}|dur| t d|¡¡S|S)a*Encode the bytes-like object s using Base64 and return a bytes object. Optional altchars should be a byte string of length 2 which specifies an alternative alphabet for the '+' and '/' characters. This allows an application to e.g. generate url or filesystem safe Base64 strings. F)ÚnewlineNó+/)ÚbinasciiÚ b2a_base64Ú translateÚbytesÚ maketrans)r"ÚaltcharsÚencodedr#r#r$r3srFcCsNt|ƒ}|durt|ƒ}| t |d¡¡}|r"t d|¡s"t d¡‚t |¡S)anDecode the Base64 encoded bytes-like object or ASCII string s. Optional altchars must be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the '+' and '/' characters. The result is returned as a bytes object. A binascii.Error is raised if s is incorrectly padded. If validate is False (the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. If validate is True, these non-alphabet characters in the input result in a binascii.Error. Nr's[A-Za-z0-9+/]*={0,2}zNon-base64 digit found) r%r*r+r,ÚreÚ fullmatchr(ÚErrorÚ a2b_base64)r"r-Zvalidater#r#r$rAs  rcCót|ƒS)zrEncode bytes-like object s using the standard Base64 alphabet. The result is returned as a bytes object. )rr!r#r#r$rZsrcCr3)aQDecode bytes encoded with the standard Base64 alphabet. Argument s is a bytes-like object or ASCII string to decode. The result is returned as a bytes object. A binascii.Error is raised if the input is incorrectly padded. Characters that are not in the standard alphabet are discarded prior to the padding check. )rr!r#r#r$rasrr's-_cCst|ƒ t¡S)zèEncode bytes using the URL- and filesystem-safe Base64 alphabet. Argument s is a bytes-like object to encode. The result is returned as a bytes object. The alphabet uses '-' instead of '+' and '_' instead of '/'. )rr*Ú_urlsafe_encode_translationr!r#r#r$rosrcCst|ƒ}| t¡}t|ƒS)aÎDecode bytes using the URL- and filesystem-safe Base64 alphabet. Argument s is a bytes-like object or ASCII string to decode. The result is returned as a bytes object. A binascii.Error is raised if the input is incorrectly padded. Characters that are not in the URL-safe base-64 alphabet, and are not a plus '+' or slash '/', are discarded prior to the padding check. The alphabet uses '-' instead of '+' and '_' instead of '/'. )r%r*Ú_urlsafe_decode_translationrr!r#r#r$rxs rzK Encode the bytes-like objects using {encoding} and return a bytes object. aƒ Decode the {encoding} encoded bytes-like object or ASCII string s. Optional casefold is a flag specifying whether a lowercase alphabet is acceptable as input. For security purposes, the default is False. {extra_args} The result is returned as a bytes object. A binascii.Error is raised if the input is incorrectly padded or if there are non-alphabet characters present in the input. a´ RFC 3548 allows for optional mapping of the digit 0 (zero) to the letter O (oh), and for optional mapping of the digit 1 (one) to either the letter I (eye) or letter L (el). The optional argument map01 when not None, specifies which letter the digit 1 should be mapped to (when map01 is not None, the digit 0 is always mapped to the letter O). For security purposes the default is None, so that 0 and 1 are not allowed in the input. s ABCDEFGHIJKLMNOPQRSTUVWXYZ234567s 0123456789ABCDEFGHIJKLMNOPQRSTUVcsR|tvrdd„|Dƒ‰‡fdd„ˆDƒt|<d‰t|tƒs#t|ƒ ¡}t|ƒd}|r3|dd|}tƒ}tj}t|}t dt|ƒdƒD]+}||||d…dƒ}|||d?||d ?d @||d ?d @||d @7}qE|d krd |dd…<t |ƒS|dkr�d|dd…<t |ƒS|dkr›d|dd…<t |ƒS|dkr¥d|dd…<t |ƒS)NcSóg|]}t|fƒ‘qSr#©r+©Ú.0Úir#r#r$Ú ªóz_b32encode..csg|] }ˆD]}||‘qqSr#r#©r9ÚaÚb©Zb32tabr#r$r;«óéórÚbigééiÿé és======iúÿÿÿés====éüÿÿÿés===éýÿÿÿéó=éÿÿÿÿ) Ú_b32tab2rrrrÚlenÚ bytearrayÚintÚ from_bytesÚranger+)Úalphabetr"Úleftoverr.rTZb32tab2r:Úcr#r@r$Ú _b32encode¥sB    ÿþ ý ú ü þ rYc Cst|tvrdd„t|ƒDƒt|<t|ƒ}t|ƒdrt d¡‚|dur1t|ƒ}| t dd|¡¡}|r7|  ¡}t|ƒ}|  d¡}|t|ƒ}t ƒ}t|}t dt|ƒdƒD]1}|||d…} d} z| D] } | d >|| } qdWn t y}t d ¡d‚w||  d d ¡7}qU|ds�|d vr”t d¡‚|r¶|r¶| d |K} |  d d ¡} d d |d} | d| …|dd…<t|ƒS)NcSsi|]\}}||“qSr#r#)r9ÚkÚvr#r#r$Ú Îr<z_b32decode..ézIncorrect paddings01óOrNrrBzNon-base32 digit foundrD>rrHrKrMéé+éûÿÿÿ)Ú_b32revÚ enumerater%rQr(r1r*r+r,ÚupperÚrstriprRrUÚKeyErrorÚto_bytes)rVr"ÚcasefoldÚmap01ÚlZpadcharsÚdecodedZb32revr:ZquantaÚaccrXZlastrWr#r#r$Ú _b32decodeÉsD    ÿ  ÿ   rmcCó tt|ƒS©N)rYÚ _b32alphabetr!r#r#r$røó rZbase32)ÚencodingcCstt|||ƒSro)rmrp)r"rhrir#r#r$r üsr )rrZ extra_argscCrnro)rYÚ_b32hexalphabetr!r#r#r$r rqr Z base32hexcCs tt||ƒSro)rmrs©r"rhr#r#r$r s r ÚcCst |¡ ¡S)zKEncode the bytes-like object s using Base16 and return a bytes object. )r(Zhexlifyrdr!r#r#r$r sr cCs4t|ƒ}|r | ¡}t d|¡rt d¡‚t |¡S)a‚Decode the Base16 encoded bytes-like object or ASCII string s. Optional casefold is a flag specifying whether a lowercase alphabet is acceptable as input. For security purposes, the default is False. The result is returned as a bytes object. A binascii.Error is raised if s is incorrectly padded or if there are non-alphabet characters present in the input. s [^0-9A-F]zNon-base16 digit found)r%rdr/Úsearchr(r1Z unhexlifyrtr#r#r$r s     r s<~s~>c s¬t|tƒs t|ƒ ¡}t|ƒ d}|r|d|}t dt|ƒd¡ |¡}‡‡‡‡fdd„|Dƒ}|rQ|sQ|ddkrFˆdd |d<|dd| …|d<d  |¡S) NrMrCz!%dIcsPg|]$}ˆr |s dnˆr|dkrdnˆ|dˆ|ddˆ|d‘qS)ózi óyií^ éUi9r#)r9Zword©ÚcharsÚchars2ÚfoldnulsÚ foldspacesr#r$r;9s û ÿ þþz_85encode..rOrwrrBó) rrrrrQÚstructÚStructZunpackÚjoin) r?r{r|Úpadr}r~ÚpaddingZwordsÚchunksr#rzr$Ú _85encode/s   û  r†)r~ÚwrapcolrƒÚadobecsºtdurdd„tddƒDƒadd„tDƒat|tt|d|ƒ‰|r$tˆ‰ˆrUt|r+dnd ˆƒ‰‡‡fd d„td tˆƒˆƒDƒ}|rPt|d ƒdˆkrP| d ¡d |¡‰|r[ˆt 7‰ˆS)aÜEncode bytes-like object b using Ascii85 and return a bytes object. foldspaces is an optional flag that uses the special short sequence 'y' instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This feature is not supported by the "standard" Adobe encoding. wrapcol controls whether the output should have newline (b'\n') characters added to it. If this is non-zero, each output line will be at most this many characters long. pad controls whether the input is padded to a multiple of 4 before encoding. Note that the btoa implementation always pads. adobe controls whether the encoded byte sequence is framed with <~ and ~>, which is used by the Adobe implementation. NcSr6r#r7r8r#r#r$r;\r<za85encode..é!évcSóg|] }tD]}||‘qqSr#)Ú _a85charsr=r#r#r$r;]rATrIrHcsg|] }ˆ||ˆ…‘qSr#r#r8©Úresultr‡r#r$r;esÿrrOró ) Ú _a85chars2rUrŒr†Ú _A85STARTÚmaxrQÚappendr‚Ú_A85END)r?r~r‡rƒrˆr…r#r�r$rGs$ ÿ  rs )r~rˆÚ ignorecharsc Cszt|ƒ}|r$| t¡std t¡ƒ‚| t¡r|dd…}n|dd…}t d¡j }g}|j }g}|j }|j } |dD]k} d| krGdkr|nn3|| ƒt |ƒd kr{d } |D] } d | | d} qWz||| ƒƒWn tj ywtd ƒd‚w| ƒq;| d kr‹|r†tdƒ‚|dƒq;|rœ| dkrœ|r—tdƒ‚|dƒq;| |vr¡q;td| ƒ‚d |¡} dt |ƒ} | r»| d| …} | S)a†Decode the Ascii85 encoded bytes-like object or ASCII string b. foldspaces is a flag that specifies whether the 'y' short sequence should be accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is not supported by the "standard" Adobe encoding. adobe controls whether the input sequence is in Adobe Ascii85 format (i.e. is framed with <~ and ~>). ignorechars should be a byte string containing characters to ignore from the input. This should only contain whitespace characters, and by default contains all whitespace characters in ASCII. The result is returned as a bytes object. z1Ascii85 encoded byte sequences must end with {!r}rIéþÿÿÿNú!Isuuuur‰éurBrryzAscii85 overflowézzz inside Ascii85 5-tupleséyzy inside Ascii85 5-tuples zNon-Ascii85 digit found: %crrM)r%Úendswithr”rÚformatÚ startswithr‘r€r�Úpackr“ÚclearrQÚerrorr‚)r?r~rˆr•ÚpackIrkZdecoded_appendZcurrZ curr_appendZ curr_clearÚxrlrŽr„r#r#r$rps\ þ      ÿ€      rsU0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~cCs2tdurdd„tDƒadd„tDƒat|tt|ƒS)z»Encode bytes-like object b in base85 format and return a bytes object. If pad is true, the input is padded with b'\0' so its length is a multiple of 4 bytes before encoding. NcSr6r#r7r8r#r#r$r;Èr<zb85encode..cSr‹r#)Ú _b85charsr=r#r#r$r;ÉrA)Ú _b85chars2Ú _b85alphabetr£r†)r?rƒr#r#r$r¾s rc Cs8tdurdgdattƒD]\}}|t|<q t|ƒ}t|ƒ d}|d|}g}t d¡j}tdt|ƒdƒD]T}|||d…}d}z|D] }|dt|}qFWn t yrt|ƒD]\}}t|durpt d||ƒd‚q]‚wz |  ||ƒ¡Wq7tj y‹t d |ƒd‚wd   |¡} |rš| d| …} | S) zqDecode the base85-encoded bytes-like object or ASCII string b The result is returned as a bytes object. NérBó~r—rryz#bad base85 character at position %dz+base85 overflow in hunk starting at byte %dr)Ú_b85decrcr¥r%rQr€r�ržrUrrr“r r‚) r?r:rXr„Úoutr¡ÚchunkrlÚjrŽr#r#r$rÌsP    ÿ  ÿÿÿûÿÿÿ réLrMrKcCsb | t¡}|s dSt|ƒtkr&| tt|ƒ¡}|sn ||7}t|ƒtkst |¡}| |¡q)z1Encode a file; input and output are binary files.TN)ÚreadÚ MAXBINSIZErQr(r)Úwrite)ÚinputÚoutputr"ÚnsÚliner#r#r$rüs   ü  örcCs( | ¡}|s dSt |¡}| |¡q)z1Decode a file; input and output are binary files.TN)Úreadliner(r2r¯)r°r±r³r"r#r#r$r s  ûrc Csˆzt|ƒ}Wnty}z d|jj}t|ƒ|‚d}~ww|jdvr0d|j|jjf}t|ƒ‚|jdkrBd|j|jjf}t|ƒ‚dS)Nz"expected bytes-like object, not %s)rXr?ÚBz-expected single byte elements, not %r from %srHz(expected 1-D data, not %d-D data from %s)rrrr rœÚndim)r"ÚmÚerrÚmsgr#r#r$Ú_input_type_checks$   €þ  ÿ  ÿýrºcCsLt|ƒg}tdt|ƒtƒD]}|||t…}| t |¡¡qd |¡S)zVEncode a bytestring into a bytes object containing multiple lines of base-64 data.rr)rºrUrQr®r“r(r)r‚)r"Úpiecesr:rªr#r#r$r$s  rcCst|ƒt |¡S)z8Decode a bytestring of base-64 data into a bytes object.)rºr(r2r!r#r#r$r/s rc Cs4ddl}ddl}z| |jdd…d¡\}}Wn)|jy@}z|j|_t|ƒtd|jdƒ| d¡WYd}~nd}~wwt}|D] \}}|dkrOt}|dkrUt }|d kr[t }|d kret ƒdSqE|r�|dd kr�t |dd ƒ�}|||jj ƒWdƒdS1sˆwYdS||j j |jj ƒdS) zSmall main programrNrHZdeutz�usage: %s [-d|-e|-u|-t] [file|-] -d, -u: decode -e: encode (default) -t: encode and decode string 'Aladdin:open sesame'rIz-ez-dz-uz-tú-Úrb)ÚsysÚgetoptÚargvr ÚstderrÚstdoutÚprintÚexitrrÚtestÚopenÚbufferÚstdin) r¾r¿ZoptsÚargsr¹ÚfuncÚor>Úfr#r#r$Úmain6s.ý€ù    "ÿrÍcCs<d}tt|ƒƒt|ƒ}tt|ƒƒt|ƒ}tt|ƒƒdS)NsAladdin:open sesame)rÃÚreprrr)Zs0Ús1Ús2r#r#r$rÅPs   rÅÚ__main__ro)NF)FN)F)FFF)9Ú__doc__r/r€r(Ú__all__r+rRrr%rrrrr,r4r5rrZ_B32_ENCODE_DOCSTRINGZ_B32_DECODE_DOCSTRINGZ_B32_DECODE_MAP01_DOCSTRINGrprsrPrbrYrmrrœr r r r r rŒr�r‘r”r†rrr¥r£r¤r¨rrZ MAXLINESIZEr®rrrºrrrÍrÅr r#r#r#r$Ús~       $/ ÿ ÿ  )H -    ÿ