Implementation notes The usual notes to keep up with the best practice in documentation. ---------------------------------------------------------------------- 0. Concept A program that: - Given some input, prints some output. Simple as that, eh? Not very complicated output either, only predefined ASCII arts, 4 patterns total. ---------------------------------------------------------------------- 1. Encode output The output is very specific this time, all from Soul Eater manga, volume 2. The trick is to get them to be small enough. This was done in a few steps: - Drawing the output: used CorelDraw 11 for this, my usual tool for drawing because I don't want to buy another drawing program. - Convert to text: netpbm + perl, also the usual tools used in previous projects. - Compressing output: custom C program and custom encoding. The most clever bit is in the encoding used, which comes in one of two forms: - Variable length offset+length pairs. Each number may be in the range from 93 to 111 to indicate that more bytes will follow, or 35 to 91 to indicate that it's the last byte. - Single character literal, encoded in ASCII characters range 112 to 125. Spending some 1 byte sequences to encode literals turns out to be more efficient (by ~40 bytes) than using offset+length alone. Note that all of these characters are ASCII clean and quote clean, meaning they can be placed in C strings without any blackslash escapes. The end result is 1677 bytes of compressed data, whereas bzip2 + uuencode would yield 1424 bytes. But then I don't think bzip2 can be written in less than 50 lines of code either, so I am fairly happy with this encoding scheme. ---------------------------------------------------------------------- 2. Decode output Decoding the output is trivial for the encoding scheme above. The slightly more interesting bit is in how the output is selected. It's some ghetto (non-cryptographically strong) hash function on command line arguments, with constants specifically selected so that "maka", "soul", "tsubaki" and "black star" will output the write text. ---------------------------------------------------------------------- 3. Testing A shell script is ran after every few lines of code change, to ensure that the 4 interesting input still produced the desired output. ---------------------------------------------------------------------- 4. Finally... Actually, the most difficult part of this project was finding a picture where Maka is smiling. Seriously. I wrote this program for no practical purpose other than to entertain myself, since it has been a long time since I had time to do anything outside of work. Although I suppose even for this, someone out there might be able to find some use for it. I hope not, though ^_^; I would rather trust suspicious sounding horoscopes than a 2 bit hash function... -- omoikane@uguu.org - http://uguu.org/