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 "
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.
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 -> 2means X should be replaced by 2
- The encoder goes from plaintext to code.
- The decoder goes from code to plaintext.