Skip to main content

Crate base256b

Crate base256b 

Source
Expand description

§Base 256 Braille

Docs

A way for wasting more memory when encoding binary in characters, but is more aesthetically pleasing! The UTF-8 Braille block is perfect for Base 256, but is using 3 bytes per character, so this will use more memory. Compared to base16/hex encoding is using 150% more memory. But this is using half of the screen space compared to base16/hex encoding.

§Motivation

I don’t like the fact that base32, base64 needs to be padded. The base16/hex notation is using to much screen space. I like the fact that in this use case braille is actually a binary representation.

§Example

This is how a 32 bytes array looks in multiples codecs.

codecdata
json[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
base16000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
base32AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPQ====
base64AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=
base85009C61O)~M2nh-c3=Iws5D^j+6crX17#SKH9337X
base256b⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟

§Reference implementation

def to_base256(data):
    out = ""
    for b in data:
        out += chr(b + 0x2800)
    return out

def from_base256(text):
    out = []
    for c in text:
        out.append(ord(c) - 0x2800)
    return out

Functions§

decode
Panics: if the text.as_bytes().len() cannot be divided by 3!
decode_bytes
⡈⡥⡬⡬⡯⠠⡗⡯⡲⡬⡤⠡ => Hello World
encode
Panics: if the bytes.len() cannot be multiplied by 3!
encode_bytes
Hello World => ⡈⡥⡬⡬⡯⠠⡗⡯⡲⡬⡤⠡