1import base64
2
3message = "Python is fun"
4message_bytes = message.encode('ascii')
5base64_bytes = base64.b64encode(message_bytes)
6base64_message = base64_bytes.decode('ascii')
7
8print(base64_message)
1>>> import base64
2>>> encoded = base64.b64encode(b'data to be encoded')
3>>> encoded
4b'ZGF0YSB0byBiZSBlbmNvZGVk'
5>>> data = base64.b64decode(encoded)
6>>> data
7b'data to be encoded'
8
1#== Decoding ==#
2
3import base64
4
5base64_message = 'UHl0aG9uIGlzIGZ1bg=='
6base64_bytes = base64_message.encode('ascii')
7message_bytes = base64.b64decode(base64_bytes)
8message = message_bytes.decode('ascii')
9
10print(message)