Day096 — AES encryption in Python

Jacky Tsang
1 min readAug 29, 2019

--

Here are the things I learned in a Python project involves encryption.

Convert string to bytes:

'abcde'.encode()

Convert bytes to string:

b"abcde".decode("utf-8")

fix ValueError: Input strings must be a multiple of 16 in length:

pad and unpad (fill up string to a multiple of 16):

pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s: s[0:-ord(s[-1])]

reference code:

--

--

No responses yet