Bubble Babble encoding / decoding library

Do you know Base64? This is a binary encoding that is widely used to store and transmit binary data using simple ASCII characters. Bubble Babble is also binary data encoding, much like Base64, but it alternates consonants and vowels to encode data as pseudo-words that can be easily pronounced.

Take for example the "1234567890" string. It will be encoded as "MTIzNDU2Nzg5MA==" with Base64, and as "xesef-disof-gytuf-katof-movif-baxux" with Bubble Babble. Doesn't the second string looks like a bit more readable?

Bubble Babble (see also the spec) also includes two features to check for string integrity which are nowhere to be found in Base64. The first one is begin and end markers. See the "x" characters at begin and end of the encoded string? These marks the begin and end of a string. The second feature is an integrated checksum to detect transmission errors.

The advantages of Bubble Babble:

  • readable string
  • pronounceable text
  • begin and end markers
  • checksum to detect transmission errors

The main disadvantage is the size of the encoded string, which is 3 times bigger than the original string, whereas Base64 is only 1.37 times bigger.

This might be really useful to exchange PGP fingerprints for example, as hexadecimal isn't really pleasant to pronounce.

This PHP implementation of Bubble Babble is easy to use:

    $encoded = \KD2\BubbleBabble::Encode('Pineapple');
    // => xigak-nyryk-humil-bosek-sonax

    $decoded = \KD2\BubbleBabble::Decode('xigak-nyryk-humil-bosek-sonax');
    // => Pineapple

If your prefer procedural code, just use:

    function babble_encode($str)
        return BubbleBabble::Encode($str);

    function babble_decode($str)
        return BubbleBabble::Decode($str);