U
    Ú²g²  ã                   @   sB   d Z eeddœdd„Zeeeedœdd„Zeeeedœd	d
„ZdS )z}Core mathematical operations.

This is the actual core RSA implementation, which is only defined
mathematically on integers.
N)ÚvarÚnameÚreturnc                 C   s$   t | tƒrd S td|| jf ƒ‚d S )Nz%s should be an integer, not %s)Ú
isinstanceÚintÚ	TypeErrorÚ	__class__)r   r   © r   ú,/tmp/pip-unpacked-wheel-1z1vrokf/rsa/core.pyÚ
assert_int   s    
r
   )ÚmessageÚekeyÚnr   c                 C   sR   t | dƒ t |dƒ t |dƒ | dk r.tdƒ‚| |krFtd| |f ƒ‚t| ||ƒS )z@Encrypts a message using encryption key 'ekey', working modulo nr   r   r   é    z'Only non-negative numbers are supportedz#The message %i is too long for n=%i)r
   Ú
ValueErrorÚOverflowErrorÚpow)r   r   r   r   r   r	   Úencrypt_int   s    


r   )Ú
cyphertextÚdkeyr   r   c                 C   s.   t | dƒ t |dƒ t |dƒ t| ||ƒ}|S )zHDecrypts a cypher text using the decryption key 'dkey', working modulo nr   r   r   )r
   r   )r   r   r   r   r   r   r	   Údecrypt_int-   s
    


r   )Ú__doc__r   Ústrr
   r   r   r   r   r   r	   Ú<module>   s   