Build an encoder and decoder

Encoding rewrites the same bytes in a different alphabet, so it hides nothing. This set covers base64 and hex, the decode that quietly succeeds on input that was never base64, and the round trip check the finished encdec.sh adds to catch it.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 You run printf 'password' | base64 -d and it exits 0. What does that tell you?
2 Why do printf '%s' 'hello' | base64 and echo 'hello' | base64 give different results?
3 Why does the finished script read hex back with printf and od rather than with xxd -r -p?
4 Why does printf '%s' 'café' | base64 give Y2Fmw6k= rather than Y2Fm6Q==?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Encode a value and decode it back

The encdec.sh you finished is saved next to you. This encodes café to hex, which shows the UTF-8 bytes rather than the latin-1 ones, then decodes a base64 string back to text. Paste both lines.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

bash encdec.sh --to hex 'café'; bash encdec.sh -d --to base64 'aGVsbG8gdGVybXV4'
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson