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:
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.
input = { text = "user:secret", secret = "SGk=" }Steps
- Return
encoded:input.textin Base64. - Add
decoded: the text that the Base64 ininput.secretstands for. - Add
hex:input.textin hex.
Show a hint
encode turns text into the coded form and decode turns it back. input.secret is
already in Base64.