# AUTOGENERATED! DO NOT EDIT! File to edit: encrypt.ipynb (unless otherwise specified).

__all__ = ['encryptAes', 'decryptAes']

# Cell
from Crypto.Cipher import AES
from beartype import beartype
from typing import Tuple


# Cell
@beartype
def encryptAes(key:bytes, data:bytes)-> Tuple[bytes,bytes]:
  '''
    note that key has to be 16 bits long
    response:
      cipherText in bytes
  '''
  cipher = AES.new(key, AES.MODE_EAX)
  ciphertext, tag = cipher.encrypt_and_digest(data)
  return ciphertext, cipher.nonce


# Cell
@beartype
def decryptAes(key:bytes, ciphertext:bytes, nonce:bytes)->bytes:
  cipher = AES.new(key, AES.MODE_EAX, nonce=nonce)
  plaintext = cipher.decrypt(ciphertext)
  return plaintext