import string
import random
#pip install pycrypto
from Crypto.Cipher import AES
key = ''.join(
random.choice(string.ascii_letters) for _ in range(AES.block_size)) #内包表記
iv = ''.join(
random.choice(string.ascii_letters) for _ in range(AES.block_size)) #内包表記
plaintext = 'fdsfsdgsgsfgs'
cipher = AES.new(key, AES.MODE_CBC, iv)
padding_length = AES.block_size - len(plaintext) % AES.block_size #paddingする文字列の長さを計算
plaintext += chr(padding_length) * padding_length #paddingする
cipher_text = cipher.encrypt(plaintext) #暗号化
print(cipher_text)
cipher2 = AES.new(key, AES.MODE_CBC, iv)
decrypted_text = cipher2.decrypt(cipher_text) #復号化
print(decrypted_text[:-decrypted_text[-1]]) #paddingした文字列を取り除いて表示