a �DOg�M�@sjddlZddlZddlZgd�ZeefZdd�Zd?dd�Zd@dd �Z d d �Z d d �Z e� dd�Z e� dd�Zdd�Zdd�ZdZdadadd�ZdAdd�Zdd�ZdBdd�ZdadadZdZdCdd �Zddddd!�d"d#�Zddd$d%�d&d'�Zd(Zda da!da"dDd)d*�Z#d+d,�Z$d-Z%e%d.d/Z&d0d1�Z'd2d3�Z(d4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,dk�rfe,�dS)E�N)�encode�decode� encodebytes� decodebytes� b64encode� b64decode� b32encode� b32decode� b16encode� b16decode� b85encode� b85decode� a85encode� a85decode�standard_b64encode�standard_b64decode�urlsafe_b64encode�urlsafe_b64decodecCsxt|t�r2z |�d�WSty0td��Yn0t|t�r@|Szt|���WStyrtd|j j �d�Yn0dS)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!�/usr/lib64/python3.9/base64.py�_bytes_from_decode_data"s     ��r#cCs,tj|dd�}|dur(|�t�d|��S|S)NF)�newline�+/)�binascii� b2a_base64� translate�bytes� maketrans)r �altchars�encodedr!r!r"r3srFcCsNt|�}|dur*t|�}|�t�|d��}|rDt�d|�sDt�d��t�|�S)Nr%s[A-Za-z0-9+/]*={0,2}zNon-base64 digit found) r#r(r)r*�re� fullmatchr&�Error� a2b_base64)r r+�validater!r!r"rAs rcCst|�S�N)rrr!r!r"rZsrcCst|�Sr2)rrr!r!r"rasrr%s-_cCst|��t�Sr2)rr(�_urlsafe_encode_translationrr!r!r"rosrcCst|�}|�t�}t|�Sr2)r#r(�_urlsafe_decode_translationrrr!r!r"rxs  rs ABCDEFGHIJKLMNOPQRSTUVWXYZ234567cs>tdur,dd�tD���fdd��D�ad�t|t�sBt|���}t|�d}|rb|dd|}t�}tj }t}t dt|�d�D]V}||||d�d�}|||d?||d ?d @||d ?d @||d @7}q�|d kr�d |dd�<nF|dk�rd|dd�<n.|dk�r d|dd�<n|dk�r6d|dd�<t |�S)NcSsg|]}t|f��qSr!�r)��.0�ir!r!r"� ��zb32encode..csg|]}�D] }||�q qSr!r!�r7�a�b�Zb32tabr!r"r9�r:��r�big��i�� �s======i�����s====������s===�������=�����) �_b32tab2� _b32alphabetrrrr�len� bytearray�int� from_bytes�ranger))r �leftoverr,rRZb32tab2r8�cr!r>r"r�s<    �� �    rc Csxtdurdd�tt�D�at|�}t|�dr8t�d��|dur^t|�}|�t� dd|��}|rj|� �}t|�}|� d�}|t|�}t �}t}t dt|�d�D]f}|||d�}d} z|D]} | d >|| } q�Wnty�t�d �d�Yn0|| �d d �7}q�|d�s|d v�r(t�d��|�rp|�rp| d |K} | �d d �} d d |d} | d| �|dd�<t|�S)NcSsi|]\}}||�qSr!r!)r7�k�vr!r!r"� �r:zb32decode..�zIncorrect paddings01�OrKrr?zNon-base32 digit foundrA>rrErHrJ��+�����)�_b32rev� enumeraterNr#rOr&r/r(r)r*�upper�rstriprPrS�KeyError�to_bytes) r �casefoldZmap01�lZpadchars�decodedZb32revr8Zquanta�accrU�lastrTr!r!r"r �s@         r cCst�|���Sr2)r&Zhexlifyr`rr!r!r"r �sr cCs4t|�}|r|��}t�d|�r*t�d��t�|�S)Ns [^0-9A-F]zNon-base16 digit found)r#r`r-�searchr&r/Z unhexlify)r rdr!r!r"r �s   r s<~s~>c s�t|t�st|���}t|� d}|r4|d|}t�dt|�d��|�}����fdd�|D�}|r�|s�|ddkr��dd |d<|dd| �|d<d �|�S) NrJr@z!%dIcsPg|]H}�r|sdn6�r$|dkr$dn&�|d�|dd�|d�qS)�zi �yi�^ �Ui9r!)r7Zword��chars�chars2�foldnuls� foldspacesr!r"r9!s�  � �z_85encode..rLrjrr?r:) rrrrrO�struct�Struct�unpack�join) r=rnro�padrprq�padding�words�chunksr!rmr"� _85encodes   � rz)rq�wrapcolrv�adobecs�tdur*dd�tdd�D�add�tD�at|tt|d|��|rHt���r�t|rVdnd�����fd d�td t����D�}|r�t|d �d�kr�|�d �d �|��|r��t 7��S)NcSsg|]}t|f��qSr!r5r6r!r!r"r9Dr:za85encode..�!�vcSsg|]}tD] }||�q qSr!)� _a85charsr;r!r!r"r9Er:TrFrEcsg|]}�||���qSr!r!r6��resultr{r!r"r9Ms�rrLr:� ) � _a85chars2rSrrz� _A85START�maxrO�appendru�_A85END)r=rqr{rvr|ryr!r�r"r/s$ �  rs )rqr|� ignorecharsc Cs�t|�}|rH|�t�s$td�t���|�t�r<|dd�}n |dd�}t�d�j }g}|j }g}|j }|j } |dD]�} d| kr�dkr�nnj|| �t |�dkr�d } |D]} d | | d} q�z||| ��Wntj y�td �d�Yn0| �qv| d k�r|�rtd ��|d�qv|�rF| dk�rF|�r?@^_`{|}~cCs2tdur$dd�tD�add�tD�at|tt|�S)NcSsg|]}t|f��qSr!r5r6r!r!r"r9�r:zb85encode..cSsg|]}tD] }||�q qSr!)� _b85charsr;r!r!r"r9�r:)� _b85chars2� _b85alphabetr�rz)r=rvr!r!r"r �s r c CsFtdur,dgdatt�D]\}}|t|<qt|�}t|� d}|d|}g}t�d�j}tdt|�d�D]�}|||d�}d}z|D]}|dt|}q�WnDt y�t|�D]&\}}t|dur�t d||�d�q��Yn0z|� ||��Wqntj �y t d|�d�Yqn0qnd � |�} |�rB| d| �} | S) N�r?�~r�rrlz#bad base85 character at position %dz+base85 overflow in hunk starting at byte %dr:)�_b85decr_r�r#rOrrrsr�rSrrr�r�ru) r=r8rUrw�outr��chunkrg�jr�r!r!r"r �sH      ����  r �LrJrHcCsX|�t�}|sqTt|�tkr>|�tt|��}|s4q>||7}qt�|�}|�|�qdSr2)�read� MAXBINSIZErOr&r'�write)�input�outputr �ns�liner!r!r"r�s    rcCs(|��}|sq$t�|�}|�|�qdSr2)�readliner&r0r�)r�r�r�r r!r!r"r�s  rc Cs�z t|�}Wn:tyF}z"d|jj}t|�|�WYd}~n d}~00|jdvrld|j|jjf}t|��|jdkr�d|j|jjf}t|��dS)Nz"expected bytes-like object, not %s)rUr=�Bz-expected single byte elements, not %r from %srEz(expected 1-D data, not %d-D data from %s)rrrrr��ndim)r �m�err�msgr!r!r"�_input_type_check�s     �  �r�cCsLt|�g}tdt|�t�D]$}|||t�}|�t�|��qd�|�S)Nrr:)r�rSrOr�r�r&r'ru)r �piecesr8r�r!r!r"r s rcCst|�t�|�Sr2)r�r&r0rr!r!r"rsrc Cs6ddl}ddl}z|�|jdd�d�\}}WnR|jy�}z8|j|_t|�td|jd�|�d�WYd}~n d}~00t}|D]@\}}|dkr�t}|dkr�t }|dkr�t }|d kr�t �dSq�|�r |dd k�r t |dd ��}|||jj �Wd�n1�s0Yn||j j |jj �dS) NrrEZdeutz�usage: %s [-d|-e|-u|-t] [file|-] -d, -u: decode -e: encode (default) -t: encode and decode string 'Aladdin:open sesame'rFz-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"�mains(�     0r�cCs<d}tt|��t|�}tt|��t|�}tt|��dS)NsAladdin:open sesame)r��reprrr)Zs0�s1�s2r!r!r"r�8s   r��__main__)N)NF)FN)F)FFF)F)/r-rrr&�__all__r)rPrr#rrrrr*r3r4rrrNrMr^rr r r rr�r�r�rzrrr�r�r�r�r r Z MAXLINESIZEr�rrr�rrr�r�rr!r!r!r"� sX     & C  )H -