INNER CODE UNIT · Python
pad
cocomelonc/meow · 2021-09-15-rev-c-1/enc-aes.py:10
def pad(s):
return s + (AES.block_size - len(s) % AES.block_size) * chr(AES.block_size - len(s) % AES.block_size)
def convert(data):
output_str = ""
for i in range(len(data)):
current = data[i]
ordd = lambda x: x if isinstance(x, int) else ord(x)
output_str += hex(ordd(current))
return output_str.split("0x")
# AES encryption
# key is randomized (16 bytes random string),
# and the key is then transform into the SHA256 hash and
# then it is used as a key for encrypting plaintext
def AESencrypt(plaintext, key):
k = hashlib.sha256(key).digest()
iv = 16 * '\x00'