Base91, how is it calculated?

I searched online to find out how basE91 is calculated. I found resources, such as this one , which indicates the characters used for a particular value, but nowhere have I found how I get this value.

I tried changing the input values ​​to binary and taking pieces of both 6 and 7 bits, but they do not work, and I get the wrong output. I don’t want the code that will do this for me, as I, who wrote it myself, I only want to know the process needed to encode a string in basE91.

+1
source share
1 answer

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).

0
source

All Articles