Learn Lua · Data formats · Lesson 3 of 4

Base64 and hex

Some systems can only carry plain letters and digits, so text or other data is rewritten using a small set of characters. Base64 is common in web requests, and hex writes each character's code as two digits:

LUA
base64.encode("user:secret")       --> "dXNlcjpzZWNyZXQ="
base64.decode("dXNlcjpzZWNyZXQ=")  --> "user:secret"
hex.encode("Hi")                   --> "4869"

What your code receives

Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.

LUA
input = { text = "user:secret", secret = "SGk=" }

Steps

  1. Return encoded: input.text in Base64.
  2. Add decoded: the text that the Base64 in input.secret stands for.
  3. Add hex: input.text in hex.
Show a hint

encode turns text into the coded form and decode turns it back. input.secret is already in Base64.