
    ;SiB                         d Z ddlZddlZddlZddlmZ  ej                  e      Z	 ddl	Z	ej                  d        G d d	      Zy# e$ r@ dZ	ej                  rej                  rej                  d       nej                  d       Y Ow xY w)
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                   0    e Zd ZdZed        Zed        Zy)AESzf
    Class that servers as an interface to encrypt and decrypt
    text through the AES IGE mode.
    c                 F   t         rt        j                  | ||      S t        j                  rt        j                  | ||      S |dt        |      dz   }|t        |      dz  d }t	        j
                  |      }g }t        |       dz  }dgdz  }t        |      D ]x  }	t        d      D ]  }
| |	dz  |
z      ||
   z  ||
<    |j                  |      }t        d      D ]  }
||
xx   ||
   z  cc<    | |	dz  |	dz  dz    }|}|j                  |       z 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_blocks               X/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/crypto/aes.pyr   zAES.decrypt_ige"   sR    %%k3;;%%k3;;#b'Q,RAiin
;'2-C"H . 	0K2Y ?b 01 45A> "!$?  #{{+<=2Y . #s1v-#. kB.{R/?"/DEC"C./	0 Z      c                    t        |       dz  }|r| t        j                  d|z
        z  } t        rt        j                  | ||      S t
        j                  rt        j                  | ||      S |dt        |      dz   }|t        |      dz  d }t        j                  |      }g }t        |       dz  }t        |      D ]  }	t        | |	dz  |	dz  dz          }
t        d      D ]  }|
|xx   ||   z  cc<    |j                  |
      }t        d      D ]  }||xx   ||   z  cc<    |}| |	dz  |	dz  dz    }|j                  |        t        |      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   s                r   r#   zAES.encrypt_igeG   s    j/B&"**R'\22J%%j#r::%%j#r::#b'Q,RAiin:", . 	2K#;+K",<r,AB  2Y . #s1v-#. !$,< =2Y /!!$A.$/ $C[2-kB.>.CDC01	2" [!!r   N)__name__
__module____qualname____doc__staticmethodr   r#    r   r   r   r      s0     "! "!H '" '"r   r   )r*   r!   r   logging r   	getLoggerr'   __log__r
   infoImportErrorr#   r   r   r,   r   r   <module>r3      s    
    '

H
%	CLLBCR" R"  CFf00FG B 	CCs   A ABB