o
    Œõ±j]k  ã                   @   sZ   d Z ddlZejd ZdZdZdZdZG dd„ deƒZ	G dd„ de	ƒZ
G d	d
„ d
e	ƒZdS )a8	  A pure python implementation of the DES and TRIPLE DES encryption algorithms.

Class initialization
--------------------
pyDes.des(key, [mode], [IV], [pad], [padmode])
pyDes.triple_des(key, [mode], [IV], [pad], [padmode])

key     -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes
	   for Triple DES
mode    -> Optional argument for encryption type, can be either
	   pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)
IV      -> Optional Initial Value bytes, must be supplied if using CBC mode.
	   Length must be 8 bytes.
pad     -> Optional argument, set the pad character (PAD_NORMAL) to use during
	   all encrypt/decrypt operations done with this instance.
padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5)
	   to use during all encrypt/decrypt operations done with this instance.

I recommend to use PAD_PKCS5 padding, as then you never need to worry about any
padding issues, as the padding can be removed unambiguously upon decrypting
data that was encrypted using PAD_PKCS5 padmode.

Common methods
--------------
encrypt(data, [pad], [padmode])
decrypt(data, [pad], [padmode])

data    -> Bytes to be encrypted/decrypted
pad     -> Optional argument. Only when using padmode of PAD_NORMAL. For
	   encryption, adds this characters to the end of the data block when
	   data is not a multiple of 8 bytes. For decryption, will remove the
	   trailing characters that match this pad character from the last 8
	   bytes of the unencrypted data block.
padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL
	   or PAD_PKCS5). Defaults to PAD_NORMAL.
	  

Example
-------
from pyDes import *

data = "Please encrypt my data"
k = des("DESCRYPT", CBC, "        ", pad=None, padmode=PAD_PKCS5)
# For Python3, you'll need to use bytes, i.e.:
#   data = b"Please encrypt my data"
#   k = des(b"DESCRYPT", CBC, b"        ", pad=None, padmode=PAD_PKCS5)
d = k.encrypt(data)
print "Encrypted: %r" % d
print "Decrypted: %r" % k.decrypt(d)
assert k.decrypt(d, padmode=PAD_PKCS5) == data


See the module source (pyDes.py) for more examples of use.
You can also run the pyDes.py file without and arguments to see a simple test.

Note: This code was not written for high-end systems needing a fast
      implementation, but rather a handy portable solution with small usage.

é    Né   é   c                   @   s†   e Zd Zeddefdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú_baseDesNc                 C   sz   |r|   |¡}|r|   |¡}d| _|r|tkrtdƒ‚|r/t|ƒ| jkr/tdt| jƒ d ƒ‚|| _|| _|| _|| _	d S )Né   ú)Cannot use a pad character with PAD_PKCS5ú2Invalid Initial Value (IV), must be a multiple of ú bytes)
Ú_guardAgainstUnicodeÚ
block_sizeÚ	PAD_PKCS5Ú
ValueErrorÚlenÚstrÚ_modeÚ_ivÚ_paddingÚ_padmode)ÚselfÚmodeÚIVÚpadÚpadmode© r   ú›/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/unicrypto/backends/pure/external/DES/DES.pyÚ__init__l   s   


z_baseDes.__init__c                 C   ó   | j S )zgetKey() -> bytes)Ú_baseDes__key©r   r   r   r   ÚgetKey~   ó   z_baseDes.getKeyc                 C   s   |   |¡}|| _dS )z*Will set the crypting key for this object.N)r	   r   ©r   Úkeyr   r   r   ÚsetKey‚   s   

z_baseDes.setKeyc                 C   r   )z#getMode() -> pyDes.ECB or pyDes.CBC©r   r   r   r   r   ÚgetMode‡   r   z_baseDes.getModec                 C   ó
   || _ dS ©z6Sets the type of crypting mode, pyDes.ECB or pyDes.CBCNr#   ©r   r   r   r   r   ÚsetMode‹   ó   
z_baseDes.setModec                 C   r   )z5getPadding() -> bytes of length 1. Padding character.)r   r   r   r   r   Ú
getPadding�   r   z_baseDes.getPaddingc                 C   s   |dur	|   |¡}|| _dS ©z5setPadding() -> bytes of length 1. Padding character.N)r	   r   )r   r   r   r   r   Ú
setPadding“   s   

z_baseDes.setPaddingc                 C   r   )z3getPadMode() -> pyDes.PAD_NORMAL or pyDes.PAD_PKCS5©r   r   r   r   r   Ú
getPadMode™   r   z_baseDes.getPadModec                 C   r%   ©zBSets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5Nr-   r'   r   r   r   Ú
setPadMode�   r)   z_baseDes.setPadModec                 C   r   )zgetIV() -> bytes)r   r   r   r   r   ÚgetIV¡   r   z_baseDes.getIVc                 C   s<   |r	t |ƒ| jkrtdt| jƒ d ƒ‚|  |¡}|| _dS )ú=Will set the Initial Value, used in conjunction with CBC moder   r   N)r   r
   r   r   r	   r   )r   r   r   r   r   ÚsetIV¥   s   

z_baseDes.setIVc                 C   sÔ   |d u r|   ¡ }|r|tkrtdƒ‚|tkrDt|ƒ| j dkr!|S |s'|  ¡ }|s4tdt| jƒ d ƒ‚|| jt|ƒ| j  | 7 }|S |tkrhdt|ƒ| j  }tdk r_||t	|ƒ 7 }|S |t
|g| ƒ7 }|S )Nr   r   zData must be a multiple of zA bytes in length. Use padmode=PAD_PKCS5 or set the pad character.r   é   )r.   r   r   Ú
PAD_NORMALr   r
   r*   r   Ú_pythonMajorVersionÚchrÚbytes©r   Údatar   r   Úpad_lenr   r   r   Ú_padData¬   s(   	ùþz_baseDes._padDatac                 C   s¦   |s|S |r|t krtdƒ‚|d u r|  ¡ }|tkr7|s |  ¡ }|r5|d | j … || j d …  |¡ }|S |t krQtdk rFt|d ƒ}n|d }|d | … }|S )Nr   r4   éÿÿÿÿ)	r   r   r.   r5   r*   r
   Úrstripr6   Úordr9   r   r   r   Ú
_unpadDataÉ   s(   ÿ
ùz_baseDes._unpadDatac                 C   sR   t dk rt|tƒrtdƒ‚|S t|tƒr'z| d¡W S  ty&   Y tdƒ‚w |S )Nr4   z4pyDes can only work with bytes, not Unicode strings.Úasciiz6pyDes can only work with encoded strings, not Unicode.)r6   Ú
isinstanceÚunicoder   r   ÚencodeÚUnicodeEncodeError)r   r:   r   r   r   r	   ä   s   
	
ùþz_baseDes._guardAgainstUnicode)Ú__name__Ú
__module__Ú__qualname__ÚECBr5   r   r   r"   r$   r(   r*   r,   r.   r0   r1   r3   r<   r@   r	   r   r   r   r   r   k   s    r   c                	   @   sâ   e Zd ZdZg d¢Zg d¢Zg d¢Zg d¢Zg d¢Zg d¢g d¢g d	¢g d
¢g d¢g d¢g d¢g d¢gZ	g d¢Z
g d¢ZdZdZeddefdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd(d$d%„Zd(d&d'„ZdS ))ÚdesaÞ  DES encryption/decrytpion class

	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.

	pyDes.des(key,[mode], [IV])

	key  -> Bytes containing the encryption key, must be exactly 8 bytes
	mode -> Optional argument for encryption type, can be either pyDes.ECB
		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
		Must be 8 bytes in length.
	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
		during all encrypt/decrypt operations done with this instance.
	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
		PAD_PKCS5) to use during all encrypt/decrypt operations done
		with this instance.
	)8é8   é0   é(   é    é   é   r   r   é9   é1   é)   é!   é   é   é	   r   é:   é2   é*   é"   é   é   é
   r   é;   é3   é+   é#   é>   é6   é.   é&   é   é   é   é   é=   é5   é-   é%   é   é   é   é   é<   é4   é,   é$   é   é   é   é   é   é   é   r4   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )0rq   rP   r^   é   r   rz   r   r{   ri   rr   rx   rW   rh   r]   r}   r4   rU   é   é   rj   r\   r|   ry   r   rM   r`   rg   rv   re   rd   ro   é'   rY   ru   rN   é/   ra   rL   rf   é7   rT   rt   rm   rS   rR   rb   rw   é   )@rQ   rR   rS   rT   rU   rV   rW   r   r_   r`   ra   rb   r{   r|   r}   r4   rk   rl   rm   rn   ro   rp   rq   rr   é?   rƒ   r‚   r�   r„   r~   r€   r   rK   rL   rM   rN   rO   rP   r   r   rX   rY   rZ   r[   r\   r]   r^   r   rs   rt   ru   rv   rw   rx   ry   rz   rc   rd   re   rf   rg   rh   ri   rj   )0r„   r   r   r   r4   rz   r4   rz   rr   rj   r   r   r   r   rW   r^   r}   ry   r}   ry   rq   ri   r€   rP   r€   rP   rV   r]   r|   rx   r|   rx   rp   rh   r~   rO   r~   rO   rU   r\   r{   rw   r{   rw   ro   rg   r„   r   )@ri   rz   rq   r   r   r€   r}   r   r4   r^   rj   ry   rr   rW   r   r   r   r€   r   rz   ri   r   rq   r   r^   rj   ry   r}   rW   rr   r4   r   rz   r   ri   r   rq   rj   r   r}   r€   ry   rW   r   r4   r^   rr   r   r€   ry   r   r   rz   rW   r   r   rr   r}   r4   ri   r^   r   rj   rq   )@r€   r   r   ri   rj   r}   r4   rz   rW   r   r   rq   ry   r   rr   r^   r4   rq   rz   r   r€   r   r   ri   ry   r   r   r^   rj   rW   r}   rr   r   ri   r   r}   r^   rz   rq   r   rr   r   ry   rj   rW   r4   r   r€   rq   r   r^   r   r4   r€   rz   r   r}   rj   r   ry   r   rr   ri   rW   )@r^   r   rW   ri   rj   r4   r€   rr   r   rq   ry   r   r}   rz   r   r   rq   r   r   rW   r4   rz   rj   r^   r   r   rr   ri   ry   r}   r€   r   rq   rj   rz   rW   r   r€   r4   r   r}   r   r   ry   rr   r^   ri   r   r   r^   rq   r   rj   rW   r   r   rz   r€   ri   r4   r}   rr   r   ry   )@r   rq   ri   r4   r   rj   rW   r^   r   r   r   rr   r}   ry   rz   r€   rq   r   r}   rr   rj   r€   r   r4   rz   r   r   ry   r   r^   ri   rW   r^   rj   rW   r   ry   r}   r   rq   r€   r   r4   ri   rr   r   r   rz   r4   r€   r   rj   r^   r   rq   r   rW   rz   rr   r}   ry   r   r   ri   )@r   ry   rz   r   r   r^   r}   rj   r   rr   r4   r€   rq   r   ri   rW   ri   r}   r   ry   rz   r   rq   r   rr   r   r€   r^   r4   rW   r   rj   rz   r   r   r}   r^   rq   r   r   r€   rW   ry   rr   rj   r4   r   ri   r}   r   ry   r   r   ri   r   rq   rj   r€   r   rW   r^   rz   rr   r4   )@ry   r   r^   r€   rW   r   rj   r   r   rq   r4   rz   ri   r   rr   r}   r^   r€   rz   r   r   ry   rW   rr   rj   r   rq   ri   r   r}   r4   r   rW   ri   r€   rr   r   r   ry   r4   r   r   rz   r^   r   rq   r}   rj   rz   r4   r   ry   rW   rr   r€   r^   r}   ri   r   r   rj   r   r   rq   )@rz   r}   r   ri   r€   r   r   rq   r4   ry   rW   r   rr   r^   rj   r   rq   r   r}   r   rz   rW   r   r^   ri   r4   rr   ry   r   r€   r   rj   r   rz   r}   rq   ry   r4   r   ri   r^   r€   rj   r   r   rr   rW   r   rj   r}   rq   r   r   rz   r^   r   rW   rr   r   r€   ri   r   r4   ry   )@rq   r   r   rz   rj   r€   r}   r   r^   rW   r4   ri   rr   r   ry   r   r   r€   rq   r   r^   r4   r   rz   ry   rr   rj   r}   r   ri   rW   r   r   r}   rz   r   rW   ry   ri   r   r   rj   r^   rq   r€   r4   rr   r   r   r   ri   r   rz   r^   r   rq   r€   ry   rW   r   r4   rr   rj   r}   ) r€   rj   r|   rx   rw   r}   r{   rP   r   ri   rh   rU   rz   rV   rg   rW   r   r   r~   rq   r„   r\   r   r   r]   ry   ro   rr   rp   r^   r4   rO   )@r�   r   r‚   r€   rƒ   r~   r…   r„   rf   rj   re   ri   rd   rh   rc   rg   rn   rr   rm   rq   rl   rp   rk   ro   rv   rz   ru   ry   rt   rx   rs   rw   rb   r4   ra   r}   r`   r|   r_   r{   r[   r   rZ   r^   rY   r]   rX   r\   rT   r   rS   rW   rR   rV   rQ   rU   rN   r   rM   r   rL   rP   rK   rO   r   r   Nc                 C   s^   t |ƒdkr
tdƒ‚t | ||||¡ d| _g | _g | _dgd gd | _g | _|  	|¡ d S )Nr   z7Invalid DES key size. Key must be exactly 8 bytes long.r   rL   rP   )
r   r   r   r   Úkey_sizeÚLÚRÚKnÚfinalr"   ©r   r!   r   r   r   r   r   r   r   r   �  s   zdes.__init__c                 C   s   t  | |¡ |  ¡  dS )z;Will set the crypting key for this object. Must be 8 bytes.N)r   r"   Ú_des__create_sub_keysr    r   r   r   r"   ›  s   z
des.setKeyc                 C   s„   t dk rdd„ |D ƒ}t|ƒd }dg| }d}|D ]%}d}|dkr?|d|> @ dkr/d||< nd||< |d7 }|d8 }|dks"q|S )z2Turn the string data, into a list of bits (1, 0)'sr4   c                 S   ó   g | ]}t |ƒ‘qS r   )r?   ©Ú.0Úcr   r   r   Ú
<listcomp>¥  ó    z+des.__String_to_BitList.<locals>.<listcomp>r   r   r   r   )r6   r   )r   r:   ÚlÚresultÚposÚchÚir   r   r   Ú__String_to_BitList   s    

ú€zdes.__String_to_BitListc                 C   s‚   g }d}d}|t |ƒk r/||| d|d  > 7 }|d dkr%| |¡ d}|d7 }|t |ƒk stdk r=d dd„ |D ƒ¡S t|ƒS )	z,Turn the list of bits -> data, into a stringr   r   r   r   r4   Ú c                 S   r�   r   )r7   rŽ   r   r   r   r‘   Â  r’   z+des.__BitList_to_String.<locals>.<listcomp>)r   Úappendr6   Újoinr8   )r   r:   r”   r•   r�   r   r   r   Ú__BitList_to_Stringµ  s   
ûzdes.__BitList_to_Stringc                    s   t t‡ fdd„|ƒƒS )z-Permutate this block with the specified tablec                    s   ˆ |  S ©Nr   )Úx©Úblockr   r   Ú<lambda>È  ó    z!des.__permutate.<locals>.<lambda>)ÚlistÚmap)r   Útabler    r   rŸ   r   Ú__permutateÆ  s   zdes.__permutatec                 C   sÐ   |   tj|  |  ¡ ¡¡}d}|dd… | _|dd… | _|dk rfd}|tj| k rN| j | jd ¡ | jd= | j | jd ¡ | jd= |d7 }|tj| k s)|   tj	| j| j ¡| j
|< |d7 }|dk s dS dS )z6Create the 16 subkeys K[1] to K[16] from the given keyr   Nrw   rP   r   )Ú_des__permutaterJ   Ú	_des__pc1Ú_des__String_to_BitListr   r‡   rˆ   Ú_des__left_rotationsrš   Ú	_des__pc2r‰   )r   r!   r—   Újr   r   r   Ú__create_sub_keysÌ  s    ù
ñzdes.__create_sub_keysc              
   C   sD  |   tj|¡}|dd… | _|dd… | _|tjkrd}d}nd}d}d}|dk �r| jdd… }|   tj| j¡| _ttdd	„ | j| j	| ƒƒ| _| jdd
… | jd
d… | jdd… | jdd… | jdd… | jdd… | jdd… | jdd… g}d}dgd }	d}
|dk rï|| d d> || d  }|| d d> || d d>  || d d>  || d  }tj
| |d> |  }|d@ d? |	|
< |d@ d? |	|
d < |d@ d? |	|
d < |d@ |	|
d < |
d7 }
|d7 }|dk sˆ|   tj|	¡| _ttdd	„ | j| jƒƒ| _|| _|d7 }||7 }|dk s*|   tj| j| j ¡| _| jS )z4Crypt the block of data through DES bit-manipulationNrN   r   r   r€   r=   rP   c                 S   ó   | |A S r�   r   ©rž   Úyr   r   r   r¡   ý  r¢   z!des.__des_crypt.<locals>.<lambda>rj   ry   r]   rO   rg   rv   rZ   r   rr   r4   r   rz   c                 S   r®   r�   r   r¯   r   r   r   r¡   !  r¢   )r§   rJ   Ú_des__ipr‡   rˆ   ÚENCRYPTÚ_des__expansion_tabler£   r¤   r‰   Ú
_des__sboxÚ_des__pÚ_des__fprŠ   )r   r    Ú
crypt_typeÚ	iterationÚiteration_adjustmentr—   ÚtempRÚBr¬   ÚBnr•   ÚmÚnÚvr   r   r   Ú__des_cryptå  sH   

d
<ñÉ:zdes.__des_cryptc           	      C   s„  |sdS t |ƒ| j dkr<|tjkrtdt| jƒ d ƒ‚|  ¡ s,tdt| jƒ d ƒ‚|| jt |ƒ| j  |  ¡  7 }|  ¡ tkrR|  	¡ rN|  
|  	¡ ¡}ntdƒ‚d}i }g }|t |ƒk r±|  
|||d … ¡}|  ¡ tkr™|tjkr~ttdd	„ ||ƒƒ}|  ||¡}|tjkr–ttd
d	„ ||ƒƒ}|}n	|}n|  ||¡}| |  |¡¡ |d7 }|t |ƒk s^tdk rºd |¡S t d¡ |¡S )z8Crypt the data in blocks, running it through des_crypt()r™   r   z0Invalid data length, data must be a multiple of z bytes
.z3 bytes
. Try setting the optional padding characterzBFor CBC mode, you must supply the Initial Value (IV) for cipheringr   c                 S   r®   r�   r   r¯   r   r   r   r¡   ^  r¢   zdes.crypt.<locals>.<lambda>c                 S   r®   r�   r   r¯   r   r   r   r¡   g  r¢   r4   )r   r
   rJ   ÚDECRYPTr   r   r*   r$   ÚCBCr1   r©   r²   r£   r¤   Ú_des__des_cryptrš   Ú_des__BitList_to_Stringr6   r›   r8   Úfromhex)	r   r:   r·   Úivr—   Údictr”   r    Úprocessed_blockr   r   r   Úcrypt4  s@   
 


×.
z	des.cryptc                 C   s8   |   |¡}|dur|   |¡}|  |||¡}|  |tj¡S )a  encrypt(data, [pad], [padmode]) -> bytes

		data : Bytes to be encrypted
		pad  : Optional argument for encryption padding. Must only be one byte
		padmode : Optional argument for overriding the padding mode.

		The data must be a multiple of 8 bytes and will be encrypted
		with the already specified key. Data does not have to be a
		multiple of 8 bytes if the padding character is supplied, or
		the padmode is set to PAD_PKCS5, as bytes will then added to
		ensure the be padded data is a multiple of 8 bytes.
		N)r	   r<   rÉ   rJ   r²   ©r   r:   r   r   r   r   r   Úencrypt‚  s
   

zdes.encryptc                 C   s8   |   |¡}|dur|   |¡}|  |tj¡}|  |||¡S )a”  decrypt(data, [pad], [padmode]) -> bytes

		data : Bytes to be decrypted
		pad  : Optional argument for decryption padding. Must only be one byte
		padmode : Optional argument for overriding the padding mode.

		The data must be a multiple of 8 bytes and will be decrypted
		with the already specified key. In PAD_NORMAL mode, if the
		optional padding character is supplied, then the un-encrypted
		data will have the padding characters removed from the end of
		the bytes. This pad removal only occurs on the last 8 bytes of
		the data (last data block). In PAD_PKCS5 mode, the special
		padding end markers will be removed from the data after decrypting.
		N)r	   rÉ   rJ   rÁ   r@   rÊ   r   r   r   Údecrypt•  s
   

zdes.decrypt©NN)rF   rG   rH   Ú__doc__r¨   rª   r«   r±   r³   r´   rµ   r¶   r²   rÁ   rI   r5   r   r"   r©   rÄ   r§   rŒ   rÃ   rÉ   rË   rÌ   r   r   r   r   rJ   ÷   s<    Ô4
O
NrJ   c                   @   s^   e Zd ZdZeddefdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zddd„Zddd„ZdS )Ú
triple_desaƒ  Triple DES encryption/decrytpion class

	This algorithm uses the DES-EDE3 (when a 24 byte key is supplied) or
	the DES-EDE2 (when a 16 byte key is supplied) encryption methods.
	Supports ECB (Electronic Code Book) and CBC (Cypher Block Chaining) modes.

	pyDes.des(key, [mode], [IV])

	key  -> Bytes containing the encryption key, must be either 16 or
	        24 bytes long
	mode -> Optional argument for encryption type, can be either pyDes.ECB
		(Electronic Code Book), pyDes.CBC (Cypher Block Chaining)
	IV   -> Optional Initial Value bytes, must be supplied if using CBC mode.
		Must be 8 bytes in length.
	pad  -> Optional argument, set the pad character (PAD_NORMAL) to use
		during all encrypt/decrypt operations done with this instance.
	padmode -> Optional argument, set the padding mode (PAD_NORMAL or
		PAD_PKCS5) to use during all encrypt/decrypt operations done
		with this instance.
	Nc                 C   s    t  | ||||¡ |  |¡ d S r�   )r   r   r"   r‹   r   r   r   r   Ä  s   ztriple_des.__init__c                 C   sø   d| _ t|ƒ| j krt|ƒdkrd| _ ntdƒ‚|  ¡ tkr7|  ¡ s*|d| j… | _t|  ¡ ƒ| jkr7tdƒ‚t|dd… | j	| j| j
| jƒ| _t|dd… | j	| j| j
| jƒ| _| j dkrc| j| _nt|dd… | j	| j| j
| jƒ| _t | |¡ dS )zFWill set the crypting key for this object. Either 16 or 24 bytes long.rO   rP   zCInvalid triple DES key size. Key must be either 16 or 24 bytes longNz%Invalid IV, must be 8 bytes in lengthr   )r†   r   r   r$   rÂ   r1   r
   r   rJ   r   r   r   Ú_triple_des__key1Ú_triple_des__key2Ú_triple_des__key3r   r"   r    r   r   r   r"   È  s,   ÿÿ

ÿztriple_des.setKeyc                 C   ó0   t  | |¡ | j| j| jfD ]}| |¡ qdS r&   )r   r(   rÐ   rÑ   rÒ   ©r   r   r!   r   r   r   r(   ã  ó   ÿztriple_des.setModec                 C   rÓ   r+   )r   r,   rÐ   rÑ   rÒ   )r   r   r!   r   r   r   r,   é  rÕ   ztriple_des.setPaddingc                 C   rÓ   r/   )r   r0   rÐ   rÑ   rÒ   rÔ   r   r   r   r0   ï  rÕ   ztriple_des.setPadModec                 C   rÓ   )r2   N)r   r3   rÐ   rÑ   rÒ   )r   r   r!   r   r   r   r3   õ  rÕ   ztriple_des.setIVc           	      C   sJ  t j}t j}|  |¡}|dur|  |¡}|  |||¡}|  ¡ tkr�| j |  	¡ ¡ | j
 |  	¡ ¡ | j |  	¡ ¡ d}g }|t|ƒk r| j |||d … |¡}| j
 ||¡}| j ||¡}| j |¡ | j
 |¡ | j |¡ | |¡ |d7 }|t|ƒk sCtdk rˆd |¡S t d¡ |¡S | j ||¡}| j
 ||¡}| j ||¡S )a  encrypt(data, [pad], [padmode]) -> bytes

		data : bytes to be encrypted
		pad  : Optional argument for encryption padding. Must only be one byte
		padmode : Optional argument for overriding the padding mode.

		The data must be a multiple of 8 bytes and will be encrypted
		with the already specified key. Data does not have to be a
		multiple of 8 bytes if the padding character is supplied, or
		the padmode is set to PAD_PKCS5, as bytes will then added to
		ensure the be padded data is a multiple of 8 bytes.
		Nr   r   r4   r™   )rJ   r²   rÁ   r	   r<   r$   rÂ   rÐ   r3   r1   rÑ   rÒ   r   rÉ   rš   r6   r›   r8   rÅ   )	r   r:   r   r   r²   rÁ   r—   r”   r    r   r   r   rË   û  s8   


ø	
ztriple_des.encryptc           
      C   sR  t j}t j}|  |¡}|dur|  |¡}|  ¡ tkr�| j |  ¡ ¡ | j	 |  ¡ ¡ | j
 |  ¡ ¡ d}g }|t|ƒk rz|||d … }| j
 ||¡}	| j	 |	|¡}	| j |	|¡}	| j |¡ | j	 |¡ | j
 |¡ | |	¡ |d7 }|t|ƒk s<tdk r„d |¡}nt d¡ |¡}n| j
 ||¡}| j	 ||¡}| j ||¡}|  |||¡S )aÂ  decrypt(data, [pad], [padmode]) -> bytes

		data : bytes to be encrypted
		pad  : Optional argument for decryption padding. Must only be one byte
		padmode : Optional argument for overriding the padding mode.

		The data must be a multiple of 8 bytes and will be decrypted
		with the already specified key. In PAD_NORMAL mode, if the
		optional padding character is supplied, then the un-encrypted
		data will have the padding characters removed from the end of
		the bytes. This pad removal only occurs on the last 8 bytes of
		the data (last data block). In PAD_PKCS5 mode, the special
		padding end markers will be removed from the data after
		decrypting, no pad character is required for PAD_PKCS5.
		Nr   r   r4   r™   )rJ   r²   rÁ   r	   r$   rÂ   rÐ   r3   r1   rÑ   rÒ   r   rÉ   rš   r6   r›   r8   rÅ   r@   )
r   r:   r   r   r²   rÁ   r—   r”   rÆ   r    r   r   r   rÌ   '  s:   


÷
ztriple_des.decryptrÍ   )rF   rG   rH   rÎ   rI   r5   r   r"   r(   r,   r0   r3   rË   rÌ   r   r   r   r   rÏ   ¯  s    
,rÏ   )rÎ   ÚsysÚversion_infor6   rI   rÂ   r5   r   Úobjectr   rJ   rÏ   r   r   r   r   Ú<module>   s   <
	    ;