Command-line tool that encodes and decodes content using the Golomb coding algorithm.
Make sure that you have the Ruby's environment installed.
$ gem install golomb-cli
After installing you have access to the command golomb
on your terminal.
Download the project and execute the command below. Make sure that you are on the project directory.
$ bundle install
This command will install all dependencies. After installed you can access the binary located in bin/golomb
. Execute the binary based on the examples below.
The tool has the commands encode
and decode
.
Use the help option to view all parameters allowed.
$ golomb --help
The example below encodes a text file using the divisor 10 and saves the encoded data into a file named my_output. The verbose option prints the symbols table.
$ golomb --divisor 10 --output my_output encode --verbose my_file.txt
You can pass a text stream to encode instead of a file.
$ golomb --divisor 10 --output my_output encode --verbose "My text goes here"
Output generated by the encode command with the verbose option:
+---------+------------------+
| Symbol table |
+---------+------------------+
| Symbol | Encode |
+---------+------------------+
| M (77) | 111111101101 |
| y (121) | 1111111111110001 |
| (32) | 1110010 |
| t (116) | 1111111111101100 |
| e (101) | 11111111110001 |
| x (120) | 1111111111110000 |
| t (116) | 1111111111101100 |
| (32) | 1110010 |
| g (103) | 11111111110011 |
| o (111) | 111111111110001 |
| e (101) | 11111111110001 |
| s (115) | 111111111110101 |
| (32) | 1110010 |
| h (104) | 11111111110100 |
| e (101) | 11111111110001 |
| r (114) | 111111111110100 |
| e (101) | 11111111110001 |
+---------+------------------+
INPUT HEX:
0x4d 0x79 0x20 0x74 0x65 0x78 0x74 0x20 0x67 0x6f 0x65 0x73 0x20 0x68 0x65 0x72 0x65
OUTPUT HEX:
0xfed 0xfff1 0x72 0xffec 0x3ff1 0xfff0 0xffec 0x72 0x3ff3 0x7ff1 0x3ff1 0x7ff5 0x72 0x3ff4 0x3ff1 0x7ff4 0x3ff1
The example below decodes the previously encoded file.
$ golomb --divisor 10 decode my_output