Hacker News new | ask | show | jobs
by barbegal 2886 days ago
I was confused as to how you could represent a bootable CD image in printable characters. It turns out that you can't. This is a tweet of a perl script which creates a cd.iso file that you can then boot from. The perl script significantly decompresses the data in the tweet.

That said, this is a playable game in around 60 bytes of actual data which is impressive.

8 comments

I'm reminded of the RSA in Perl "weapon" t-shirt :)

https://upload.wikimedia.org/wikipedia/commons/9/96/Munition...

Machine readable as well as machine washable[0]!

[0]: http://cypherpunks.venona.com/archive/1995/10/msg00317.html

Man that shirt is awesome... But man I would never wear that shirt as that looks like the crown jewel of any neckbeards collection
It sounds like you've been trained to hate something that you actually love. That's kind of sad. Couldn't you just wear the awesome shirt while avoiding the negative aspects of neckbeards?
Not CD images, but there is DOS C compiler generating executables with only printable characters (and also no self-modifying code that could contain non-printable characters)

http://www.cs.cmu.edu/~tom7/abc/paper.txt (view in monospace font, 160 character lines)

That said, this is a playable game in around 60 bytes of actual data which is impressive.

.. and way smaller than your comment .

It's pretty light compression from what I can tell - basically just squashing down runs of nulls to a single count.
The compression is basic run-length encoding, leveraging the Perl repetition operator (x), and the property of the Perl print/say functions that they concat items passed in a list before writing to STDOUT.

https://en.wikipedia.org/wiki/Run-length_encoding

https://perldoc.perl.org/perlop.html#Multiplicative-Operator...

https://perldoc.perl.org/functions/say.html

https://perldoc.perl.org/functions/print.html

I tried xz -9 on it and found, to my surprise, that it was actually longer than RLE!

Then I tried gzip -9, because perhaps that has a smaller header? Yup, saved a few bytes, now it's about the same size. Finally, I remembered that bzip2 does a lot better on text than gzip, and who knows, it might also have a shorter header than xz. Again, a few more bytes saved! Down to 223, where the original is 249 bytes (including the 'say' part but excluding the unnecessary delimiting apostrophes or the rest of the command).

Took me a second to figure out after looking at the assembly that it's possible because of base64.
Yeah, it's a really simple run-length encoded ISO expressed as a Perl script.
I looked at the that tweet for five or six minutes and was stumped. Now this makes more sense, thanks.
Most of the "compression" is zero bytes due to fixed offsets of various things (e.g. the first 16 sectors of an ISO 9660 image are a "system area" not used by the actual file system).