TUT language translator Text may be translated to a written version of TUT language by replacing each letter by the corresponding "TUT word", as given in the following table (adapted from the linked article)*:

a  e        h  hash     o  o        u  yu
b  bub      i  ay       p  pup      v  vuv
c  kut      j  jag      q  kwak     w  waks
d  dud      k  kak      r  rut      x  eks
e  i        l  lul      s  sus      y  yak
f  fuf      m  mum      t  tut      z  zuz
g  jug      n  nun            

* Exceptions: 
(1) Upper case letters have corresponding TUT words in upper case.
(2) A doubled letter becomes 'skwer' ('SKWER') followed by the TUT word for that letter.
    - An n-fold letter is treated as a number of doubles, followed by a single if needed.
    - To be considered a double or n-fold letter, the letters must be in the same case.
(3) 'rut' ('RUT') is replaced by 'rud' ('RUD') if immediately followed by 'dud' ('DUD'). 


Write a program with the following i/o behavior:

Input (from stdin): A binary (0/1) indicator i and an ASCII string s. 


If i = 0 then s may contain any ASCII text.
If i = 1 then s must be the TUT Language output for some valid input.


Output (to stdout): A binary (0/1) indicator j and an ASCII string t.  


If i = 0 then j = 1 and t is the translation of s to TUT Language.
If i = 1 then j = 0 and t is the translation of s from TUT Language.   
For any valid input, applying the program to its own output must exactly reproduce the original input; i.e., program (program (i, s)) = (i, s). Input and output must have exactly the same format.


Scoring: The score is the number of characters in the program -- lowest score wins.

Examples

(a)

(0, 'Look for the birds.')
(1, 'LULskwerokak fuforut tuthashi bubayruddudsus.')


(b)

(0, '"Mrs. Hogwallop up and R-U-N-N-O-F-T."')
(1, '"MUMrutsus. HASHojugwakseskwerlulopup yupup enundud RUT-YU-NUN-NUN-O-FUF-TUT."')


(c)

(0, 'QWX WWW Rrrrd deeeeep')
(1, 'KWAKWAKSEKS SKWERWAKSWAKS RUTskwerrutruddud dudskweriskweriipup')


(d)

(0, 'aa AA aA Aa rd RD rD Rd')
(1, 'skwere SKWERE eE Ee ruddud RUDDUD rutDUD RUTdud)


(((Aside about pronunciation: The TUT words for the vowels (e, i, ay, o, yu) are supposed to represent the usual sounds of (a, e, i, o, u) when reciting the alphabet -- i.e., rhyming with (may, me, my, mow, mew). In the three-or-more-letter TUT words, the symbols (u,a,e) are supposed to sound as in (but, bat, bet) respectively -- these are ASCII replacements for (ʌ æ ɛ)  in the linked article.)))
Ruby, 310 311 characters
h=Hash[(?a..?z).zip %w{e bub kut dud i fuf jug hash ay jag kak lul mum nun o pup kwak rut sus tut yu vuv waks eks yak zuz}]
h[&quot;rd&quot;]=&quot;ruddud&quot;
h.keys.each{|k|h[k[0]+k]=&quot;skwer&quot;+h[k]}
h.keys.each{|k|h[k.upcase]=h[k].upcase}
h=h.invert if b=getc==?1
i=gets
print b ?0:1;(k=i;k=k.chop until h[k]||!k[1];$&gt;&lt;&lt;(h[k]||k);i[k]=&quot;&quot;)until i==&quot;&quot;

Correctly handles:

squared uppercase (unfix by merging iterations gains 18 characters)

if AA should turn into skwerE, swap lines #3 and #4
I also assume aA and Aa should turn into eE and Ee respectively


rrd translates to `skwerruddud (unfix gains 3 characters)
in cubes the first pair is reported as a square. rrrd turns into skwerrutruddud. rrrrd becomes skwerrutskwerruddud
the output is now a valid input. It is, indeed, required by the spec
uses newline as input terminator

Input requires there be no newline between the indicator and the string, output puts it there (fix: 1 character). Console output suppressed at this point to prevent mixing with STDIN. Unfix free, it's just a little bit uglier.
Example input:
0Hello

Output:
1
HASHiskwerlulo