There can be multiple solutions.
- Use decimal representation of each byte. To enable restoring of the original byte stream from 0-9 stream, each 0-9 representation should contain exactly 3 symbols, means, use leading zeroes for numbers less than 100. The transformation would look as follows:
- 00000000 -> 000
- 00000001 -> 001
- 00000010 -> 002
- 00000011 -> 003
- 00100000 -> 032
- 11111111 -> 255
The frequency of every digit will be not equal, 0 and 1 will have the highest frequency, then 2, then all the others. But this does does not change anything on the entropy of the original data that these 0-9 encoding represents.
The advantage of this approach is that for conversion a single byte at a time is sufficient. For restoring of the byte 3 digits at a time are sufficient.
- Use decimal representation of each 4 bits.
- 0000 -> 00
- 0001 -> 01
- 0010 -> 02
- 0011 -> 03
- 1010 -> 10
- 1111 -> 15
Thus each byte will be represented with 4 digits 0-9.
The advantage is the same as in case with whole byte: For encoding you need 1 byte at a time, for decoding 2 digits 0-9. A disadvantage is, that the result will need more space, 4 digits for each byte instead of 3.
- You can use group of bytes, e.g. consider every 2 bytes or every 8 bytes as a decimal number. Don't forget about leading zeroes.
However such groups of bytes would have a disadvantage, that you would need to use padding. E.g. if you use groups of 8 bytes and the last group has less than 8 bytes, this would need extra byte to build a group of 8.