D = 4096; // Dictionary (a.k.a. sliding window / ring / buffer) size All variables (FLAGS, N, O, L) initialized as 0. REMEMBER! When writing to output below and after 2.2. (N > 0), write every byte also in dictionary, advancing dictionary offset by one. Once offset reaches the end of the dictionary, drop it back to the start (normally 0). REMEMBER! Clearing dictionary means replacing it's contents with spaces (character #32, hex 0x20), not 0 or other value! 0. Set dictionary offset to D-18 1. If at the end of file, exit (duh). 2. Read N (2 bytes == word) from input. The absolute value of N is how many bytes of data to read (if N=0, exit, duh) 2.1. If N < 0, read the absolute value of N bytes from input and write to output (do not put into dictionary). Go to 1. 2.2. If N > 0, clear dictionary, repeat below until N bytes have been read from input, and then go to 1. 2.2.1. Read FLAGS (1 byte) from input. Repeat below 8 times. 2.2.1.1. If FLAGS *is not* a modulus of 2 (& 1 != 0), read 1 byte from input, write to output, then go to 2.2.1.3. 2.2.1.2. If FLAGS *is* a modulus of 2 (& 1 == 0) 2.2.1.2.1. Read O (1 byte) and L (1 byte) from input. 2.2.1.2.2. Take away the High-nibble (first 4 bits) from L and prepend it to O; 2.2.1.2.3. Read L+3 bytes from dictionary at offset O, and write them to the output. 2.2.1.3. Divide FLAGS by 2, rounding down (>> 1).