The three rules of Ruby Quiz:

1.  Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2.  Support Ruby Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3.  Enjoy!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

The quoted printable encoding is used in primarily in email, thought it has
recently seen some use in XML areas as well.  The encoding is simple to
translate to and from.

This week's quiz is to build a filter that handles quoted printable translation.

Your script should be a standard Unix filter, reading from files listed on the
command-line or STDIN and writing to STDOUT.  In normal operation, the script
should encode all text read in the quoted printable format.  However, your
script should also support a -d command-line option and when present, text
should be decoded from quoted printable instead.  Finally, your script should
understand a -x command-line option and when given, it should encode <, > and &
for use with XML.

Here are the rules we will use, from the quoted printable format:

	1.  Bytes with ASCII values from 33 (exclamation point) through 60 (less
	    than) and values from 62 (greater than) through 126 (tilde) should be
	    passed through the encoding process unchanged.  Note that the -x switch
	    modifies this rule slightly, as stated above.
	
	2.  Other bytes are to be encoded as an equals sign (=) followed by two
	    hexadecimal digits.  For example, when -x is active less than (<) will
	    become =3C.  Use only capital letters for hex digits.
	
	3.  The exceptions are spaces and tabs.  They should remain unencoded as
	    long as any non-whitespace character follows them on the line.  Spaces
	    and tabs at the end of a line, must be encoded per rule 2 above.
	
	4.  Native line endings should be translated to carriage return-line feed
	    pairs.
	
	5.  Quoted printable lines are limited to 76 characters of length (not
	    counting the line ending pair).  Longer lines must be divided up.  Any
	    line endings added by the encoding process should be proceeded by an
	    equals sign, so the unecoder will know to remove them.  The equals sign
	    must be the last character on the line, followed immediately by the line
	    end pair.  Such an equals sign does count as a non-whitespace character
	    for rule 3, allowing preceding spaces and tabs to remain unencoded. 
	    The equals sign must fit inside the 76 character limit.

To unecode, just reverse the process.