Tic Tac Toe encoder/decoder James Bond is about to start a new mission and you are his computer scientist friend. As Tic Tac Toe is becoming more and more popular you decide that nothing would be more underhanded than a Tic Tac Toe encoder/decoder™. 

For each line the decoder will follow the following steps:


Convert from 'O','X' and ' ' [space] to trinary


' ' -> 0
'O' -> 1
'X' -> 2

Convert from trinary to decimal
Convert from decimal to letter


Example: "XO "


210
21
v


The encoder will do the reverse.

As code is much more precise than words, see the reference answer below in which I give an example (very long) implementation of the problem in Python:

Your decoder should be able to decode all the messages encoded with my encoder correctly and my decoder should be able to decode all the messages encoded with your encoder.

This is code-golf, the shortest wins.

Additional informations


0 must be converted to a, the alphabet ends with a whitespace, so 26-> ' ' [whitespace]
"XXX" is the max, it translates to "222" that translates to 26.
As in Tic Tac Toe the max line lenght is 3.
X -&gt; 2 means X should be replaced by 2
Encoder/Decoder


The encoder goes from plaintext to code.
The decoder goes from code to plaintext.
C++, 168 + 135 = 303 bytes



EDIT: saved one byte by requiring uppercase input

I like doing these in C++ because I get to do all sorts of fun nastiness I would never ever do in C++ code.

Encoder (168):

Takes a string of uppercase letters and spaces as an argument.

#include&lt;cstdio&gt;
int main(int h,char**c){c[0][3]=0;for(c++;h=**c;c[0]++){h=h&amp;32?26:h-65;for(int d=2,e;d+1;d--){h=(h-(e=h%3))/3;c[-1][d]=e&amp;2?88:e*47+32;}printf(c[-1]);}}


Readable:

#include&lt;cstdio&gt;
int main(int h,char**c)
{
    c[0][3]=0;
    for(c++;h=**c;c[0]++)
    {
        h=h&amp;32?26:h-65;
        for(int d=2,e;d+1;d--)
        {
            h=(h-(e=h%3))/3;
            c[-1][d]=e&amp;2?88:e*47+32;
        }
        printf(c[-1]);
    }
}


Decoder (135):

Takes a string of X, O, and space as an argument.

#include&lt;cstdio&gt;
int b=9,v;int main(int h,char**c){for(c++;h=**c;c[0]++){v+=(h&amp;16?2:h&amp;1)*b;b/=3;if(!b)putchar(v==26?32:v+97),v=0,b=9;}}


Readable:

#include&lt;cstdio&gt;
int b=9,v;
int main(int h,char**c)
{
    for(c++;h=**c;c[0]++)
    {
        v+=(h&amp;16?2:h&amp;1)*b;
        b/=3;
        if(!b)putchar(v==26?32:v+97),v=0,b=9;
    }
}