o
    XzjB  ã                   @   s”   d Z ddlZddlZddlZddlmZ e e¡Zzddl	Z	e 
d¡ W n ey@   dZ	ejr9ejr9e 
d¡ ne 
d¡ Y nw G dd	„ d	ƒZdS )
z¶
AES IGE implementation in Python.

If available, cryptg will be used instead, otherwise
if available, libssl will be used instead, otherwise
the Python implementation will be used.
é    Né   )Úlibsslz/cryptg detected, it will be used for encryptionz/libssl detected, it will be used for encryptionz\cryptg module not installed and libssl not found, falling back to (slower) Python encryptionc                   @   s(   e Zd ZdZedd„ ƒZedd„ ƒZdS )ÚAESzf
    Class that servers as an interface to encrypt and decrypt
    text through the AES IGE mode.
    c                 C   s  t r	t  | ||¡S tjrt | ||¡S |dt|ƒd … }|t|ƒd d… }t |¡}g }t| ƒd }dgd }t|ƒD ]@}	tdƒD ]}
| |	d |
  ||
 A ||
< qC| |¡}tdƒD ]}
||
  ||
 N  < q]| |	d |	d d … }|}| |¡ q=t	|ƒS )z
        Decrypts the given text in 16-bytes blocks by using the
        given key and 32-bytes initialization vector.
        Né   é   r   )
ÚcryptgÚdecrypt_iger   ÚlenÚpyaesr   ÚrangeÚdecryptÚextendÚbytes)Úcipher_textÚkeyÚivÚiv1Úiv2ÚaesÚ
plain_textÚblocks_countÚcipher_text_blockÚblock_indexÚiÚplain_text_block© r   úN/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/crypto/aes.pyr   "   s*   

ÿ
zAES.decrypt_igec                 C   s0  t | ƒd }|r| t d| ¡7 } trt | ||¡S tjr$t | ||¡S |dt |ƒd … }|t |ƒd d… }t |¡}g }t | ƒd }t|ƒD ]J}	t	| |	d |	d d … ƒ}
tdƒD ]}|
|  || N  < q]| 
|
¡}tdƒD ]}||  || N  < qs|}| |	d |	d d … }| |¡ qIt|ƒS )z
        Encrypts the given text in 16-bytes blocks by using the
        given key and 32-bytes initialization vector.
        r   Nr   )r	   ÚosÚurandomr   Úencrypt_iger   r
   r   r   ÚlistÚencryptr   r   )r   r   r   Úpaddingr   r   r   r   r   r   r   r   r   r   r   r   r   G   s2   
ÿ
zAES.encrypt_igeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r   r   r      s    
$r   )r&   r   r
   ÚloggingÚ r   Ú	getLoggerr#   Ú__log__r   ÚinfoÚImportErrorr   r   r   r   r   r   r   Ú<module>   s"    

€û	