# MicroPython + AES256 on ESP32
# Docs: https://docs.micropython.org/en/latest/library/ucryptolib.html
  
import uos
from ucryptolib import aes
  
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 = "This text is a very top secret!"
print('Input: {}'.format(plain))
  
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('')
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23