Giter VIP home page Giter VIP logo

offset248's Introduction

Offset248

Offset248 is a technique for encoding binary to text that can be easily copied and pasted. Rather than encoding bytes to another base, Offset248 keeps the data in base 256 and simply renders the each byte into a unicode character.

###Method

The character used for each byte is a standard unicode character offset by 248. So if you have a byte value of 0, you select the unicode character 248 ("ø").

For example, the Wikidata favicon (101 bytes) encodes to:

ƁňņĿąĂĒĂøøøąŁŀļŊøøøĈøøøĈĀþøøøėǫǷřøøøĤŁļĹŌŰǒśŘĐĖŘĞûƻŷŜĄĊīƖƑǮėżƹĂNJŞǶĿƹǠǪƛþƄĒĸčûžĮøøğźǟđǩĒąĤøøøøŁĽņļƦĺŘź

###Benefits

  1. This offset was chosen because every character in the range 248-503 is recognized as a character and not a separator. Thus, when you print out the encoding, you can double click the text and the entire row will highlight. This makes for easy copy and pasting of data.

  2. The character length of the encoded string is the byte length of the binary data. This can be helpful when you are character constrained (like Twitter) rather than byte constrained and base64 or base58 encoding is too large.

  3. Encoders and decoders are super simple. No splitting bytes or bitwise operations. Just an integer offest.

###Full Character Map

øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷ

###Example Encoders/Decoders

####Python

def encode(input):
    return u"".join(unichr(b + 248) for b in input) #use chr() for Python 3

def decode(input):
    return [ord(c) - 248 for c in input]

test = [1,3,3,7]
encoded = encode(test) #u"ùûûÿ"
decoded = decode(encoded)
print u"[1,3,3,7] => \"{}\", test={}".format(encoded, test == decoded)

####Javascript

function encode(input) {
    for(var i = 0, output = ""; i < input.length; i++)
        output += String.fromCharCode(input[i] + 248);
    return output;
}

function decode(input) {
    for(var i = 0, output = []; i < input.length; i++)
        output.push(input.charCodeAt(i) - 248);
    return output;
}

var test = [1,3,3,7]; //can be Uint8Array, too
var encoded = encode(test); //"ùûûÿ"
var decoded = decode(encoded);
console.log("[1,3,3,7] => \"%s\", test=%s", encoded, test.toString() === decoded.toString());

Pull Requests Wanted! Add an encoder and decoder for your favorite language

###License

All documentation and example code is released as public domain.

offset248's People

Contributors

diafygi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.