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.
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:
M
→ 115(8)a
→ 141(8)n
→ 156(8)
Put every digit (octet, actually) together:
115141156
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.
Octal | Character | Other option |
---|---|---|
11 | → I 111(8) |
|
51 | → i 151(8) |
→ ) 051(8) |
41 | → a 141(8) |
→ ! 041(8) |
15 | → M 115(8) |
|
60 | → p 160(8) |
→ 0 060(8) |
Finally, put every character together into a string. Each 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:
a. IAeMalMx`JyoNQlL`a
(backtick)
b. IAeMalMx JyoNQlL a
(space)
c. IAeMalMxàJyoNQlLàa
(agrave)
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.
Download 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"
v0.0.1 alpha
- Handle Unicode characters properly so emojis can be used (using
String#codepoints
?) - Explain motivation in this Readme.
- Write down some ideas where Ease64 can be used.