Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String to string compression algorithm?

I'm looking for an algorithm that would compress some string to another string (i.e. without "\0" or special control characters), but I can't find anything on the internet. Is there such an algorithm? It doesn't have to be particularly efficient, just something basic.

like image 598
laurent Avatar asked Nov 01 '25 09:11

laurent


1 Answers

Easy:

$ echo "Hello world" | gzip -c | base64
H4sIALnHeU4AA/NIzcnJVyjPL8pJ4QIA1eA5twwAAAA=

$ echo "H4sIALnHeU4AA/NIzcnJVyjPL8pJ4QIA1eA5twwAAAA=" | base64 -d | gzip -dc
Hello world

Note: looks like there is no compression, but for bigger data the compression ratio will be better :-)

like image 141
Tomas Avatar answered Nov 03 '25 10:11

Tomas