Ease64 (alpha). Base64 for humans
Ease64 is a Base64 alternative that can be encoded/decoded by hand. This means: no error-prone math operations like addition (uuencode) and no arbitrary look-up tables. All that's needed is a regular ASCII-octal table for both encoding and decoding.
For more, continue reading this or look at the tests.
Encoding by hand
Let's encode the word "
Man". First, get yourself an ASCII table with octals in it. It's not that difficult.
Then, look up every character and write down their octal values:
Put every digit (octet, actually) together:
Now separate the octets in groups of two, add one zero at the end if needed:
11 51 41 15 60
Then, go back to the same ASCII table and look up your two octets. As you see, most values are three octets long. The key here is to ignore the third octet from the right. In some cases, you will have more than one character to choose from. That's fine.
Finally, put every character together into a string. Every one of the next eight results are 100% ease64 valid and decode back to "
Man". Use whichever you prefer:
IiaMp IiaM0 I)aMp I)aM0 Ii!Mp Ii!M0 I)!Mp I)!M0
Hello World! may be encoded into any of the following:
IAeMalMx JyoNQlL a (space)
All three examples decode back to
Hello World!. Why?
Unlike Base64, for any value that you want to encode, you can choose between different characters as long as they follow this rule: its octal value must share the last two digits. Be careful with text encodings if you get very fancy and start using emojis, special characters and the like.
ease64.rb in the same directory of your project.
require_relative 'ease64' enc = Ease64.encode64 'Hello World!' # => "IAeMalMx`JyoNQlL`a" plain = Ease64.decode64 enc # => "Hello World!"
To play in the console with interactive Ruby:
$ irb -r './ease.rb' 2.3.0 :001 > Ease64.encode64 'Hello World!' # => "IAeMalMx`JyoNQlL`a"
- Handle Unicode characters properly so emojis can be used (using
- Explain motivation in this Readme.
- Write down some ideas where Ease64 can be used.