\d$RdZddlZddlZddlZgdZeefZdZd6dZ d7dZ dZ d Z e d d Ze d d Zd Zd ZdZdZdZdZdZiaiadZd8dZdZede_d8dZedee_dZede_d9dZedde_dZ d9dZ!da"da#d Z$d!Z%d:d"Z&ddddd#d$Z'ddd%d&d'Z(d(Z)da*da+da,d9d)Z-d*Z.d+Z/e/d,zd-zZ0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7e8d5kr e6dSdS);zDBase16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodingsN)encodedecode encodebytes decodebytes b64encode b64decode b32encode b32decode b32hexencode b32hexdecode b16encode b16decode b85encode b85decode a85encode a85decodestandard_b64encodestandard_b64decodeurlsafe_b64encodeurlsafe_b64decodecZt|tr3 |dS#t$rt dwxYwt|t r|S t |S#t$rtd|j j zdwxYw)Nasciiz4string argument should contain only ASCII charactersz>argument should be a bytes-like object or ASCII string, not %r) isinstancestrrUnicodeEncodeError ValueError bytes_types memoryviewtobytes TypeError __class____name__ss ..\python\lib\base64.py_bytes_from_decode_datar&"s!SU U88G$$ $! U U USTT T U![!!K!}}$$&&& KKK)+,;+?@AAFJ KKs,A! B(B*ctj|d}|Xt|dksJt||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_base64lenrepr translatebytes maketrans)r$altcharsencodeds r%rr3sk!!U333G8}}!!!4>>!!!  !A!ABBB NFct|}|gt|}t|dksJt||t|d}t j||S)aDecode 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. For more information about the strict base64 check, see: https://docs.python.org/3.11/library/binascii.html#binascii.a2b_base64 Nr)r*) strict_mode)r&r-r.r/r0r1r+ a2b_base64)r$r2validates r%rrAs~$ ""A*8448}}!!!4>>!!! KK%88 9 9  qh 7 7 77r4c t|S)zrEncode bytes-like object s using the standard Base64 alphabet. The result is returned as a bytes object. )rr#s r%rr[s Q<<r4c t|S)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#s r%rrbs Q<<r4r*s-_cPt|tS)zEncode 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#s r%rrps Q<< ! !"= > >>r4crt|}|t}t|S)aDecode 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#s r%rrys/ ""A /00A Q<<r4zK 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 0123456789ABCDEFGHIJKLMNOPQRSTUVc|tvr$d|DfdDt|<dt|ts!t|}t |dz}|r |dd|z zz}t }tj}t|}tdt |dD]P}||||dz}|||dz ||dz dzz||d z dzz||dzzz }Q|d krd |d d<n)|d krd|dd<n|dkrd|dd<n |dkrd|dd<t|S)Nc.g|]}t|fSr0.0is r% z_b32encode..s 000!%++000r4c$g|] }D]}||z SrArA)rDabb32tabs r%rFz_b32encode..s*DDDVDDa!eDDDDr4ri s======ir)s====s====) _b32tab2rrrrr- bytearrayint from_bytesranger0) alphabetr$leftoverr3rZb32tab2rEcrJs @r% _b32encoder`sx00x000DDDDVDDD a % %$ qMM ! ! # #1vvzH' X& &kkGJx G 1c!ffa  JqAE{ # #GAG$Q"W-./Q"W-./AI&'  1}}  Q Q Q >>r4c4|tvr!dt|Dt|<t|}t|dzrt jd|jt|}t|dksJt ||t dd|z}|r| }t|}| d}|t|z }t}t|}tdt|dD]a}|||dz} d} | D]} | d z|| z} n##t$rt jd dwxYw|| d z }b|dzs|d vrt jd|r9|r7| d |zz} | d } d d |zz dz} | d| |d d<t|S)Nci|]\}}|| SrArA)rDkvs r% z_b32decode..sBBBdaQBBBr4zIncorrect paddingrPs01OrUrrKzNon-base32 digit found>rrPrRrT+)_b32rev enumerater&r-r+Errorr.r/r0r1upperrstriprXr[KeyErrorto_bytes)r\r$casefoldmap01lpadcharsdecodedb32revrEquantaaccr_lastr]s r% _b32decoder{s=wBBi.A.ABBB""A 1vvz2n0111 '..5zzQU  KKte|<< = = GGII AA A3q66zHkkG X F 1c!ffa ##1a!e8 E - -ax6!9, - E E E.!9:: D E3<<??"1u2//n0111'G' H ||AX%!+IXI >>s #E77 Fc,tt|SN)r` _b32alphabetr#s r%r r s lA & &&r4base32)encodingc0tt|||Sr})r{r~)r$rrrss r%r r s lAx 7 77r4)r extra_argsc,tt|Sr})r`_b32hexalphabetr#s r%r r s oq ) ))r4 base32hexc.tt||Sr})r{rr$rrs r%r r s oq( 3 33r4cNtj|S)zKEncode the bytes-like object s using Base16 and return a bytes object. )r+hexlifyrnr#s r%r r s!  A   $ $ & &&r4ct|}|r|}tjd|rt jdt j|S)aDecode 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&rnresearchr+rm unhexlifyrs r%rrs\ ""A GGII yq!!7n5666  a  r4s<~s~>ct|ts!t|}t | dz}|r|d|zz}t jdt |dzz|}fd|D}|r0|s.|ddkrddz|d<|dd| |d<d |S) NrTrLz!%dIc|g|]8}r|sdn/r|dkrdn%|dz|dzdzz|dzz9S)zi yi^ Ui9rA)rDwordcharschars2foldnuls foldspacess r%rFz_85encode..:s!!!  !t!dd !TZ%7%7dddfn%dbj4'()TBY !!!r4rVrrrKr4) rrrrr-structStructunpackjoin) rIrrpadrrpaddingwordschunkss `` `` r% _85encoder0s a % %$ qMM ! ! # #Aw!mG   M&CFFaK0 1 1 8 8 ; ;E!!!!!!!  !!!F+s+ ":  qAF2JBZ ' *r 88F  r4)rwrapcolradobect+dtddDadtDat|tt|d||r tzrt |rdndfd td t D}|r1t |d dzkr|d d ||r tz S)aEncode 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. Nc.g|]}t|fSrArBrCs r%rFza85encode..]s 999QUA4[[999r4!vc,g|]}tD]}||zSrA) _a85charsrDrHrIs r%rFza85encode..^)DDD!)DDQq1uDDDDr4Tr)rPc*g|]}||zSrArA)rDrEresultrs r%rFza85encode..fs6;;;AK(;;;r4rrVr4 ) _a85chars2r[rr _A85STARTmaxr-appendr_A85END)rIrrrrrrs ` @r%rrHs(99%C..999 DDyDDD q)ZdJ G GF $V#$5'aaa11;;;;; CKK99;;;  #6":"W,, c"""F## ' Mr4s )rr ignorecharsct|}|rp|ts'tdt|t r |dd}n |dd}tjdj }g}|j }g}|j }|j } |dzD]} d| cxkrdkrwnnt|| t|d krUd } |D] } d | z| dz z}  ||| n##tj $rtd dwxYw| | d kr|rtd|d|r#| dkr|rtd|d| |vrtd| zd|} dt|z } | r | d| } | S)aDecode 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}r)N!IsuuuururKrrzAscii85 overflowzzz inside Ascii85 5-tuplesyzy inside Ascii85 5-tuples zNon-Ascii85 digit found: %cr4rT)r&endswithrrformat startswithrrrpackrclearr-errorr)rIrrrpackIrvdecoded_appendcurr curr_append curr_clearxryrrs r%rrqs\ ""A zz'"" "F7OO  << " " !B$AA#2#A M$   $EG^N D+KJ \@@ a " " " "7 " " " " " KNNN4yyA~~..As(a"f-CCC"N55::....|CCC$%788dBC '\\ = !;<<< N; ' ' ' '  @ALL = !;<<< N. / / / / +   :Q>?? ? XXg  F#d))mG# ' " Ms <D D1sU0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~ct"dtDadtDat|tt|S)zEncode 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. Nc.g|]}t|fSrArBrCs r%rFzb85encode..s 777QUA4[[777r4c,g|]}tD]}||zSrA) _b85charsrs r%rFzb85encode..rr4) _b85chars2 _b85alphabetrr)rIrs r%rrsD77,777 DDyDDD Q :s 3 33r4ct*dgdzattD]\}}|t|<t|}t | dz}|d|zz}g}t jdj}tdt |dD]}|||dz}d} |D]}|dzt|z}nG#t$r:t|D](\}}t|td||zzd)wxYw | ||#t j $rtd |zdwxYwd |} |r | d| } | S) zqDecode the base85-encoded bytes-like object or ASCII string b The result is returned as a bytes object. NrK~rrrz#bad base85 character at position %dz+base85 overflow in hunk starting at byte %dr4)_b85decrlrr&r-rrrr[r rrrr) rIrEr_routrchunkryjrs r%rrs&3,l++  DAqGAJJ""AAw!mG D7NA C M$   $E 1c!ffa ,,!AE'   , ,Bh+ ,   !%(( 9 911:%$%J'(1u&.//489&     , JJuuSzz " " " "| , , ,J !""'+ , ,XXc]]F# ' " Ms'CADD''#E LrTrRcX |t}|sdSt|tkrJ|tt|z }|sn||z }t|tkJtj|}||)z1Encode a file; input and output are binary files.TN)read MAXBINSIZEr-r+r,write)inputoutputr$nslines r%rrs  JJz " "  E!ffz!!Js1vv-..B  GA !ffz!! "1%% T r4c |}|sdStj|}||B)z1Decode a file; input and output are binary files.TN)readliner+r7r)rrrr$s r%rr sG~~  E   % % Q r4cH t|}n1#t$r$}d|jjz}t||d}~wwxYw|jdvr&d|jd|jj}t||jdkr%d|j|jjfz}t|dS)Nz"expected bytes-like object, not %s)r_rIBz#expected single byte elements, not z from rPz(expected 1-D data, not %d-D data from %s)rr r!r"rndim)r$merrmsgs r%_input_type_checkrs& qMM &&&2Q[5IInn#%& x&&&+,888Q[5I5IKnnv{{9+,61;3G*HInn{s A;Ac t|g}tdt|tD];}|||tz}|t j|?Bhqk  JE ]]38ABB<99 dd <Z  c  e    D++1 99Vd 99Vd 99Vd 99dffffff 99eElllFFF9 2Q3 $q'4  'A DCJ% & & & ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' SY sz011111s)&A B ?BB EE Ecd}tt|t|}tt|t|}tt|||ksJdS)NsAladdin:open sesame)rr.rr)s0s1s2s r%rrTsa B $r((OOO RB $r((OOO RB $r((OOO 888888r4__main__r})NF)FN)F)FFF)9__doc__rrr+__all__r0rXrr&rrrrr1r<r>rr_B32_ENCODE_DOCSTRING_B32_DECODE_DOCSTRING_B32_DECODE_MAP01_DOCSTRINGr~rrWrkr`r{r rr r r r rrrrrrrrrrrrrr MAXLINESIZErrrrrrrrr"rAr4r%r stKJ     $i  K K K"    88884$ooeU;;#ooeU;;???   $ 3 5  """H,,,,^''')00(0CC 8888)00(3N1PP ***,33[3II 4444-33[?A4CC ''' !!!!*    0 %aU%'''''R %E|DDDDDPE    4 4 4 4'''Z 1na         """222: zDFFFFFr4