B
    ¸hþ  ã               @   sJ   d dl mZmZmZmZmZmZ eddƒZddd„Zddd„Z	d	d
„ Z
dS )é    )Úload_pycryptodome_raw_libÚc_size_tÚcreate_string_bufferÚget_raw_bufferÚc_uint8_ptrÚis_writeable_bufferzCrypto.Util._strxoray  
                    void strxor(const uint8_t *in1,
                                const uint8_t *in2,
                                uint8_t *out, size_t len);
                    void strxor_c(const uint8_t *in,
                                  uint8_t c,
                                  uint8_t *out,
                                  size_t len);
                    Nc             C   sž   t | ƒt |ƒkrtdƒ‚|dkr.tt | ƒƒ}n4|}t|ƒsBtdƒ‚t | ƒt |ƒkrbtdt | ƒ ƒ‚t t| ƒt|ƒt|ƒtt | ƒƒ¡ |dkr–t	|ƒS dS dS )aØ  XOR two byte strings.
    
    Args:
      term1 (bytes/bytearray/memoryview):
        The first term of the XOR operation.
      term2 (bytes/bytearray/memoryview):
        The second term of the XOR operation.
      output (bytearray/memoryview):
        The location where the result must be written to.
        If ``None``, the result is returned.
    :Return:
        If ``output`` is ``None``, a new ``bytes`` string with the result.
        Otherwise ``None``.
    z.Only byte strings of equal length can be xoredNz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input  (%d bytes))
ÚlenÚ
ValueErrorr   r   Ú	TypeErrorÚ_raw_strxorÚstrxorr   r   r   )Úterm1Úterm2ÚoutputÚresult© r   úOC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\Crypto\Util\strxor.pyr   /   s"    
r   c             C   s    d|  krdk sn t dƒ‚|dkr4tt| ƒƒ}n4|}t|ƒsHtdƒ‚t| ƒt|ƒkrht dt| ƒ ƒ‚t t| ƒ|t|ƒtt| ƒƒ¡ |dkr˜t	|ƒS dS dS )aî  XOR a byte string with a repeated sequence of characters.

    Args:
        term(bytes/bytearray/memoryview):
            The first term of the XOR operation.
        c (bytes):
            The byte that makes up the second term of the XOR operation.
        output (None or bytearray/memoryview):
            If not ``None``, the location where the result is stored into.

    Return:
        If ``output`` is ``None``, a new ``bytes`` string with the result.
        Otherwise ``None``.
    r   é   zc must be in range(256)Nz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input  (%d bytes))
r	   r   r   r   r
   r   Ústrxor_cr   r   r   )ÚtermÚcr   r   r   r   r   r   Z   s"    
r   c             C   s   t  | ||tt| ƒƒ¡ dS )z!Very fast XOR - check conditions!N)r   r   r   r   )r   r   r   r   r   r   Ú_strxor_direct†   s    r   )N)N)ÚCrypto.Util._raw_apir   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s
    	
+
,