Hashing, encoding and basic security · 8 / 15 Exercise Medium

Encode and decode in Base64

Objective

Base64 represents any bytes with 64 printable characters, so they can be sent through channels that only accept text (email, JSON, URLs). It is not encryption: anyone can decode it.

Instructions

  • The first line has the number n of commands; each one is enc text (encodes the text in UTF-8) or dec base64 (decodes).
  • Show the result. If the base64 string is not valid or does not represent UTF-8 text, show Error: invalid base64. Decode with validate=True.
Input
3
enc hola mundo
dec aG9sYQ==
dec !!!
Output
aG9sYSBtdW5kbw==
hola
Error: invalid base64

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise