U
    '1eh                     @   s   d Z d ZdZddlmZ G dd dZdddd	dd
dd	d
d
dd	dddd	dddd	gZdd Zdd Z	e
dkrdZeD ]8Zeed ed Zeed ed Zed7 ZqdS )z
Arciv Stream  ciphering
zArcIV encode decodez1.0    )	isUnicodec                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ArcIVz
	performs 'ArcIV' Stream Encryption of S using key
	Based on what is widely thought to be RSA's ArcIV algorithm.
	It produces output streams that are identical.

	NB there is no separate decoder arciv(arciv(s,key),key) == s
	c                 C   s   || _ |   d S )N)_keyreset)selfkey r   7/tmp/pip-unpacked-wheel-109iniqw/reportlab/lib/arciv.py__init__   s    zArcIV.__init__c                 C   s   | j }t|r|d}ttd}ttd}t|}|D ]}|||  d ||< q<d}tdD ]6}|||  ||  d }|| ||  ||< ||< qb|dd  | _| _| _dS )z&restore the cipher to it's start stateutf8   r   N)	r   r   encodelistrangelen_sbox_i_j)r   r   sboxkZlkijr   r   r	   r      s     
zArcIV.resetc                 C   s   | j | j| j  }}}t|tr.t|dnt|tr@t|n
|dd }t|}d}||k r|d d  | _}|||  d  | _}|| ||  ||< ||< || ||| ||  d  A ||< |d7 }qX|S )zn
		return the list of encoded bytes of B, B might be a string or a
		list of integers between 0 <= i <= 255
		r   Nr      r   )	r   r   r   
isinstancestrr   r   bytesr   )r   Br   r   r   Cnpr   r   r	   _encode*   s    6$
zArcIV._encodec                 C   s   t | |S )zArcIV encode string S)r   r    )r   Sr   r   r	   r   ?   s    zArcIV.encodeN)__name__
__module____qualname____doc__r
   r   r    r   r   r   r   r	   r   	   s
   r   s   #Egs   uŖ)r   inputoutputs           s   tKys   A7]:s   #Es
             s
   ֡A<8߽as   s   uJ	xJR3I=vS4IwǊ+f]S՜&ĐmkGZDz^Ngy
2DOw&Vu ~Ī;B1zCݥ
m1xNIZΐrG_b	;S/GP#q2}DD2sg/]DgPuKpw#k[tG9mbt!=.Dn5Nw=5X\	)/fK@Uo')BdE]SL㢷UW&Rn#S[ٜs]=58g-{꥕ؿo	l lzb>L=3> UW"ԸiI՝NyXkKjtԛKK$7,U5I z=ṟ͆`:ԫ4=BXU@h<(MLXq7Tq&Ԟ'U@c                 C   s   t || S )z.One-line shortcut for making an encoder objectr   r   textr   r   r   r	   r      s    r   c                 C   s   t || S )zOne-line shortcut for decodingr(   r)   r   r   r	   decode   s    r+   __main__r   r&   r'   r   N)r%   split__all____version__Zreportlab.lib.utilsr   r   Z_TESTSr   r+   r"   r   tor   r   r   r	   <module>   sD   ;4 