First, you need to see the input as a stream of bits.
Then, read 13 bits from the stream and form an integer value from it. If the value of this integer is less than or equal to 88, read one extra bit and put it on the 14th bit (the least significant bit is the 1st) of the integer. This is an integer (let it be called v ) the maximum value: 8192 + 88 = 8280.
Then divide v into two indexes: i0 = v%91 , i1 = v/91 . Then use the 91-element character table and print two characters: table[i0] , table[i1] .
(now you can see reason 88: for the maximum value (8280), both i0 and i1 become 90)
Thus, this process is more complex than base64, but more efficient. In addition, unlike base64, the size of the output is slightly dependent on the input bytes. The N-length of the sequence 0x00 will be shorter than the N-length of the sequence 0xff (where N is a sufficiently large number).
source share