# MicroPython + AES256 on ESP32
# Docs: https://docs.micropython.org/en/latest/library/ucryptolib.html
  
import uos
from ucryptolib import aes
from utime import sleep
  
key = b'[Secret Wokwi key with 256 bits]'
iv = b'secret-iv-123456' # In real life, uos.urandom(16)

MODE_CBC = 2
cipher = aes(key, MODE_CBC, iv)

plain = input("Escriba el mje: ")
print('Input: {}'.format(plain))
print("encriptando") 
sleep(4)
print("Using AES{}-CBC cipher".format(len(key * 8)))

# AES works in 16-bytes blocks, so we must pad the input text
padded = plain + " " * (16 - len(plain) % 16)
encrypted = cipher.encrypt(padded)
print('Encrypted: {}'.format(encrypted))
  
decipher = aes(key, MODE_CBC, iv)
decrypted = decipher.decrypt(encrypted)
print('Decrypted: {}'.format(decrypted.strip()))
print('')