o
    @@£il  ã                   @   s   d Z G dd„ dƒZdS )aH  
In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher.
While it is remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure.
It is especially vulnerable when the beginning of the output keystream is not discarded, or when nonrandom or related keys are used.
Particularly problematic uses of RC4 have led to very insecure protocols such as WEP.

As of 2015, there is speculation that some state cryptologic agencies may possess the capability to break RC4 when used in the TLS protocol.
IETF has published RFC 7465 to prohibit the use of RC4 in TLS; Mozilla and Microsoft have issued similar recommendations.

A number of attempts have been made to strengthen RC4, notably Spritz, RC4A, VMPC, and RC4+.
c                   @   s@   e Zd ZdZdd„ Zdd„ Zdefdd„Zded	efd
d„ZdS )ÚRC4ah  
    In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher.
    While it is remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure.
    It is especially vulnerable when the beginning of the output keystream is not discarded, or when nonrandom or related keys are used.
    Particularly problematic uses of RC4 have led to very insecure protocols such as WEP.

    As of 2015, there is speculation that some state cryptologic agencies may possess the capability to break RC4 when used in the TLS protocol.
    IETF has published RFC 7465 to prohibit the use of RC4 in TLS; Mozilla and Microsoft have issued similar recommendations.

    A number of attempts have been made to strengthen RC4, notably Spritz, RC4A, VMPC, and RC4+.
    c                 C   s$   d| _ d| _dd„ tdƒD ƒ| _d S )Né    c                 S   ó   g | ]}|‘qS © r   ©Ú.0Únr   r   úY/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/borb/io/read/encryption/rc4.pyÚ
<listcomp>%   ó    z RC4.__init__.<locals>.<listcomp>é   )Ú_pÚ_qÚrangeÚ_state©Úselfr   r   r   Ú__init__"   s   zRC4.__init__c                 C   st   | j d d | _ | j| j| j   d | _| j| j | j| j  | j| j < | j| j< | j| j| j  | j| j  d  S )Né   r   )r   r   r   r   r   r   r   Ú_byte_generator+   s   

þ"zRC4._byte_generatorÚkeyc                 C   sš   dd„ t dƒD ƒ| _d| _d| _d}t dƒD ]4}t|ƒdkr0|| j|  ||t|ƒ   d }n	|| j|  d }| j| | j| | j|< | j|< qd S )Nc                 S   r   r   r   r   r   r   r   r	   5   r
   z RC4._set_key.<locals>.<listcomp>r   r   )r   r   r   r   Úlen)r   r   ÚjÚir   r   r   Ú_set_key4   s   $$ûzRC4._set_keyÚinputc                    s    ˆ   |¡ t‡ fdd„|D ƒƒS )a  
        This function encrypts a given byte array with a given key,
        returning the encrypted bytes.
        :param key:     the key to be used for encrypting
        :param input:   the input byte array to be encrypted
        :return:        the encrypted bytes
        c                    s   g | ]}|ˆ   ¡ A ‘qS r   )r   )r   Úpr   r   r   r	   M   s    zRC4.encrypt.<locals>.<listcomp>)r   Úbytes)r   r   r   r   r   r   ÚencryptD   s   
zRC4.encryptN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r      s    		r   N)r!   r   r   r   r   r   Ú<module>   s   