Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Base64 Coding and Decoding

base64.livemd

Base64 Coding and Decoding

Introduction

Base64 is a popular binary-to-text encoding scheme, that functions by mapping binary data to a sequence of elements from a set of 64 printable characters. This is useful when one has to transmit binary data across a channel that only reliably support text content. One example could be a URL.

This workbook uses the Base module, which is part of the standard library and implements support base16 and base32 in addition to base64.

Test Suite

suite = [
  "hello, world",
  "æøåÆØÅ",
  "[1, 3.14]"
]

Encoding

coded =
  suite
  |> Enum.map(&Base.encode64/1)

Decoding

decoded =
  coded
  |> Enum.map(&Base.decode64!/1)

Validation

suite == decoded