[Question]
  [
## Introduction:
*I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the second one (the [Computer Cipher](https://codegolf.stackexchange.com/q/176931/52210) was the first one I posted).*
---
For the [Trifid Cipher](https://en.wikipedia.org/wiki/Trifid_cipher) (without using a keyword) the alphabet (and an additional wildcard) is divided into three 3 by 3 tables:
```
table 1:     table 2:     table 3:
 |1 2 3       |1 2 3       |1 2 3
-+-----      -+-----      -+-----
1|a b c      1|j k l      1|s t u
2|d e f      2|m n o      2|v w x
3|g h i      3|p q r      3|y z  
```
A text we want to encipher is first character by character encoded into table-row-column numbers. For example, the text `this is a trifid cipher` becomes:
```
        t h i s   i s   a   t r i f i d   c i p h e r
table:  3 1 1 3 3 1 3 3 1 3 3 2 1 1 1 1 3 1 1 2 1 1 2
row:    1 3 3 1 3 3 1 3 1 3 1 3 3 2 3 2 3 1 3 3 3 2 3
column: 2 2 3 1 3 3 1 3 1 3 2 3 3 3 3 1 3 3 3 1 2 2 3
```
We then put everything after one another row by row in the table above in groups of three:
```
311 331 331 332 111 131 121 121 331 331 313 133 232 313 332 322 313 313 132 333 313 331 223
```
And those are transformed back to characters using the same tables:
```
s   y   y   z   a   g   d   d   y   y   u   i   q   u   z   w   u   u   h       u   y   o
```
One thing to note, the input-length should be coprime to 3. So if the length is a multiple of 3, we append one or two trailing spaces to make the input-length not a multiple 3 anymore.
## Challenge:
Given a string `sentence_to_encipher`, encipher it as described above.
You only have to encipher given the `sentence_to_encipher`, so no need to create a deciphering program/function as well. I might make a part 2 challenge for the deciphering in the future however (although I have the feeling it's to trivial/similar to the enciphering process).
## Challenge rules:
* You can assume the `sentence_to_encipher` will only contain letters and spaces.
* You can use either full lowercase or full uppercase (please state which one you've used in your answer).
* You can choose to append either one or two trailing spaces when the input-length is 3 to make it not a multiple of 3 anymore.
* I/O is flexible. Both input and output can be a string, list/array/stream of characters, etc.
## General rules:
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer with [default I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/), so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code (i.e. [TIO](https://tio.run/#)).
* Also, adding an explanation for your answer is highly recommended.
## Test cases:
```
Input:            "this is a trifid cipher"
Output:           "syyzagddyyuiquzwuuh uyo"
Input:            "test"
Output:           "utbk"
Input:            "output"
Possible outputs: "rrvgivx" (one space) or "rrzcc lr" (two spaces)
Input:            "trifidcipher"
Possible output:  "vabbuxlzz utr" (one space) or "vabbyzv rx ie " (two spaces)
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~29~~ ~~26~~ 25 bytes
```
⁶Øa;3ṗ¤,©Ṛy;⁶$L3ḍƊ¡ZFs3®y
```
[Try it online!](https://tio.run/##y0rNyan8//9R47bDMxKtjR/unH5oic6hlQ93zqq0Bgqq@Bg/3NF7rOvQwii3YuND6yr/H25/1LRGIfL/f6WSjMxiBSBKVCgpykzLTFFIzizISC1S0lFQKkktLgHR@aUlBaVgFkQJVAUA "Jelly – Try It Online")
### How it works
```
⁶Øa;3ṗ¤,©Ṛy;⁶$L3ḍƊ¡ZFs3®y  Main link. Argument: s (string)
⁶                          Set the return value to space.
 Øa;                       Append it to "a...z".
    3ṗ¤                    Yield the third Cartesian power of [1, 2, 3].
       ,©                  Pair the results and store the pair in the register.
                           The register now holds
                           [[[1, 1, 1], ..., [3, 3, 3]], ['a', ... ,'z', ' '].
         Ṛ                 Reverse the outer array.
           ;⁶$             Append a space to s...
              L3ḍƊ¡        if the length is divisible by 3.
          y                Transliterate according to the mapping to the left.
                   ZFs3    Zip/transpose, flatten, split into chunks of length 3.
                       ®y  Transliterate according to the mapping in the register.
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 39 bytes
```
≔Ｅ⁺θ× ¬﹪Ｌθ³⌕βιθ⭆⪪Ｅ⁺÷θ⁹⁺÷θ³θ﹪ι³¦³§⁺β ↨³ι
```
[Try it online!](https://tio.run/##ZY7BCoMwEETv/YrgaYX05Kl4spSCUItgfyA1QRfSRM0q/ft01UIPncMuO7Dzpu3V1HplYyxCwM5BpQao7RxglOKBLxMgEYkUd09QeT1bDzfjOuphTKXIUpYUV3QanlLgeoxpfqgndAQN8erWwGawSL/o0tEFF9RmhZz459/NtiQeXyhusN0vqHTavPcsxnJBds8qGMi2Eqw8RjKB4nGxHw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔               Assign
   θ            Input string
  ⁺             Concatenated with
                Literal space
    ×           Repeated
         θ      Input string
        Ｌ       Length
       ﹪        Modulo
          ³     Literal 3
      ¬         Logical not
 Ｅ              Mapped over characters
             ι  Current character
           ⌕    Position found in
            β   Lowercase alphabet
              θ To variable
     θ                      List of positions
    ÷                       Vectorised integer divide by
      ⁹                     Literal 9
   ⁺                        Concatenated with
         θ                  List of positions
        ÷                   Vectorised integer divide by
          ³                 Literal 3
       ⁺                    Concatenated with
           θ                List of positions
  Ｅ                         Map over values
             ι              Current value
            ﹪               Modulo
              ³             Literal 3
 ⪪                          Split into
                ³           Groups of 3
⭆                           Map over groups and join
                   β        Lowercase alphabet
                  ⁺         Concatenated with
                            Literal space
                 §          Cyclically indexed by
                       ι    Current group
                     ↨      Converted from
                      ³     Base 3
                            Implicitly print
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~180~~ ~~176~~ ~~174~~ ~~165~~ 163 bytes
```
lambda s:''.join(chr(32+(33+a*9+3*b+c)%59)for a,b,c in zip(*[iter(sum(zip(*[(c/9,c/3%3,c%3)for c in map(o,s+' '[len(s)%3:])]),()))]*3))
o=lambda c:(ord(c)%32-1)%27
```
[Try it online!](https://tio.run/##dU/LboMwELzzFSsqhA20UbGqKkj5hvae5mAbE9wS7PpBgn@eElIpaauu9rI7szszenSt6sup2bxNHT2wmoKt0vThXcke8dYgUuaIkJxm65xkLOc4eVrjRhmgBSs4yB6C1CjbSicMsv6ALiPiq3XBVyQhBU/IcrCQD1QjVdg8hXTbiR5ZnJBqh3e4QBjjXUYwjtTm2wmvkDI1mjVJef@Ik/J50kb2DhoUu1ZamJuCM7KRNXCpW2FiHN29eKe9q@BasR3HQPd1PY5efvpw9L4FP6o4iq4PhXX/XHvHPm6paqGcya/KWsk6AZeVrSA2ZtjL4RQDUr0AqykXGOb4MxA4h87MiDuqC2LxrYMlyDXHr@ezpXigjPlTFwJ4Z/5KnOExDGBOIAX8FJq@AA "Python 2 – Try It Online")
Input can be upper or lower. Output is uppercase
[Answer]
# Pyth, ~~34~~ 33 bytes
```
m@+G;id3csCmtj+27x+G;d3+W!%lz3zd3
```
Full program. Input is expected as lowercase, output is a character array. Try it online [here](https://pyth.herokuapp.com/?code=m%40%2BG%3Bid3csCmtj%2B27x%2BG%3Bd3%2BW%21%25lz3zd3&input=this%20is%20a%20trifid%20cipher&debug=0), or verify all test cases at once [here](https://pyth.herokuapp.com/?code=m%40%2BG%3Bid3csCmtj%2B27x%2BG%3Bd3%2BW%21%25lz3zd3&test_suite=1&test_suite_input=this%20is%20a%20trifid%20cipher%0Atest%0Aoutput%0Atrifidcipher&debug=0).
```
m@+G;id3csCmtj+27x+G;d3+W!%lz3zd3   Implicit: z=input(), d=" ", G=lowercase alphabet
                           lz       Length of z
                          %  3      The above, mod 3
                        W!          If the above != 3...
                       +      zd    ... append a space to z
           m                        Map the elements of the above, as d, using:
                  +G;                 Append a space to the lowercase alphabet
                 x   d                Find the 0-based index of d in the above
              +27                     Add 27 to the above
             j        3               Convert to base 3
            t                         Discard first element (undoes the +27, ensures result is 3 digits long)
          C                         Transpose the result of the map
         s                          Flatten
        c                       3   Split into chunks of length 3
m                                   Map the elements of the above, as d, using:
     id3                              Convert to decimal from base 3
 @+G;                                 Index the above number into the alphabet + space
                                    Implicit print
```
Alternative 34 byte solution: `sm@+G;id3csCm.[03jx+G;d3+W!%lz3zd3` - rather than +27 and tail, uses `.[03` to pad with 0 to length 3. Can be 33 if the leading `s` is dropped.
*Edit: saved a byte by dropping leading `s` as character arrays are valid output*
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~153~~ ~~145~~ ~~138~~ 131 bytes
```
->a{a<<" "if a.size%3<1;a.map{|c|[(b=(c.ord%32-1)%27)/9,b%9/3,b%3]}.transpose.join.scan(/.{3}/).map{|x|((x.to_i(3)+65)%91+32).chr}}
```
[Try it online!](https://tio.run/##LYzrioMwFIT/9ymCEJr0ckRDu8javojIckwjplATkgjdNXl2624XhpmB@Rg3dd9Lf1mOV5yxrjOS6Z4geP2jqKiLT4QH2jnK2LDuwiQYd6OiPBaclh88rw4drXKxumgTBIejt8YruBs9gpc4shxmkXL@fnlGxp4QzJdmgu/PJ06rYi9KDnJwKS3NJguD9mQVkuB0r29Eajsolx3WSfnwm2YKdvprb@Sf2LSgUA5zDNGSvgnrJzrf7rbbtLwA "Ruby – Try It Online")
A quick and naive approach, works with lowercase text. Inputs and outputs arrays of characters.
[Answer]
# [Java (JDK)](http://jdk.java.net/), 192 bytes
```
s->{String T="",R=T,C=T,r=T;for(int c:s){c-=c<33?6:97;T+=c/9;R+=c%9/3;C+=c%3;}for(var S:(s.length%3<1?T+2+R+2+C+2:T+R+C).split("(?<=\\G...)"))r+=(char)((Byte.valueOf(S,3)+65)%91+32);return r;}
```
[Try it online!](https://tio.run/##bVDfa9swEH7PX3EYDNLsqDRmLbGjhs2wsYdRSPzW9EFT7USZIxvpHAjBf3sqxSZ0rELH3Xf33c@9OIrp/u3vRR3axiDsHWYdqpp9ySb/@apOS1SN/jRo0ZTi4EOyFtbCb6E0nCcAbfenVhIsCnTq2Kg3OLgYWaNRevvyCsJsLb1SAX6MLRZyJ8zLazyQnqDiFzt9Og8QCh4E8YoXce7E8CKrGkOURpCppWc55XKRJMuHdP6YFRGXd/Ns5VQ4v0uy3BtJ1vuMozCwTolldam3uAuTxf2yiGbRykkezdLCWTlltq0VkoAsF3yz@ckYowGlJuLEz0gJ@X7Ckh1F3ZXPFVnHCY0evtJwfh8lM5qZEjujwWT9JbtueFsbS4sW@Li4fwHulAX3BThS5Q4lVbsrTRB/oLisj7jpsO3@8QypY@bo7ofefunxhL5OOsxAbyOsTxbLA3M1WetYWJHgl3blU4BNEFon@vnaL73hUAfxtUwMFRNtW5@IRwyb3F3nmzHiRCilQ/9@4qW/vAM "Java (JDK) – Try It Online")
Very naive approach. Takes a lowercase `char[]` as input but outputs a `String`.
## Explanations
```
s->{                                       // char[]-accepting lambda
 String T="",                              //  declare variables Table as an empty string,
        R=T,                               //                    Row as an empty string,
        C=T,                               //                    Column as an empty string,
        r=T;                               //                    result as an empty string.
 for(int c:s){                             //  for each character
  c-=c<33?6:97;                            //   map each letter to a number from 0 to 25, space to 26.
  T+=c/9;                                  //   append the table-value to Table
  R+=c%9/3;                                //   append the row-value to Row
  C+=c%3;                                  //   append the column-value to Column
 }                                         //
 for(var S:                                //  For each token of...
     (s.length%3<1?T+2+R+2+C+2:T+R+C)      //    a single string out of table, row and column and take the space into account if the length is not coprime to 3...
      .split("(?<=\\G...)"))               //    split every 3 characters
  r+=(char)((Byte.valueOf(S,3)+65)%91+32); //   Parses each 3-characters token into a number, using base 3,
                                           //  and make it a letter or a space
 return r;                                 //  return the result
}
```
## Credits
* -14 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
[Answer]
# [R](https://www.r-project.org/), 145 bytes
```
function(s,K=array(c(97:122,32),rep(3,3)))intToUtf8(K[matrix(arrayInd(match(c(utf8ToInt(s),32[!nchar(s)%%3]),K),dim(K))[,3:1],,3,byrow=T)[,3:1]])
```
[Try it online!](https://tio.run/##LY7BCsIwDIZfZQ4GCcSD60Ed7gFk13kaO9RuZQXXljZDffpZdRBI/nz5@RNWnV32q16sYuMsRGpqGYJ8g4LzsTqUJYkSKYweBAlENJZbd2N9gqabJQfzgt/91Q6QtJqScUm4dVfLEDHZu51VkwxJFIXokRqkwczQIHYkqkNPJOj@Du5Zt9umxzVK7x/fL3KeTMxSySylaTNkyvhpDDnlPEZOzS3sl@/w5xtG0rh@AA "R – Try It Online")
I/O as strings; adds one space. The strange repetition of `[,3:1]` is because R's natural array indexing is somewhat different.
[Answer]
# APL+WIN, 102 bytes
```
⎕av[n[c⍳(⊂[2]((⍴t),3)⍴,⍉⊃(c←⊂[2]c,(,⍉9 3⍴c←9/⍳3),[1.1]27⍴⍳3)[(⎕av[n←(97+⍳26),33])⍳t←t,(3|⍴t←⎕)↓' '])]]
```
Explanation:
```
t←t,(3|⍴t←⎕)↓' ' Prompts for input and applies coprime condition
(⎕av[n←(97+⍳26),33]⍳ Indices of characters in APL atomic vector 
c←⊂[2]c,(,⍉9 3⍴c←9/⍳3),[1.1]27⍴⍳3) Create a matrix of table, row column for 27 characters
⊂[2]((⍴t),3)⍴,⍉⊃ Extract columns of c corresponding to input and re-order
c⍳ Identify Column indices of re-ordered columns
⎕av[.....] Use indices back in atomic vector to give enciphered text  
```
Example of screen shot of test case:
```
⎕av[n[c⍳(⊂[2]((⍴t),3)⍴,⍉⊃(c←⊂[2]c,(,⍉9 3⍴c←9/⍳3),[1.1]27⍴⍳3)[(⎕av[n←(97+⍳26),33])⍳t←t,(3|⍴t←⎕)↓' '])]]
⎕:
'output'
rrvgivx  
```
[Answer]
**SAS, 305 bytes**
A hearty 'oof' for this SAS monstrosity. There's a lot of random string formatting that I thought I could avoid going into this; I'm sure there are better ways of doing some of this.
```
data;input n:&$99.;n=tranwrd(trim(n)," ","{");if mod(length(n),3)=0then n=cats(n,'{');f=n;l=length(n);array a(999);do i=1to l;v=rank(substr(n,i,1))-97;a{i}=int(v/9);a{i+l}=mod(int(v/3),3);a{i+l*2}=mod(v,3);end;f='';do i=1to l*3by 3;f=cats(f,byte(a{i}*9+a{i+1}*3+a{i+2}+97));end;f=tranwrd(f,"{"," ");cards;
```
Input is entered on newlines after the cards statement, like so:
```
data;input n:&$99.;n=tranwrd(trim(n)," ","{");if mod(length(n),3)=0then n=cats(n,'{');f=n;l=length(n);array a(999);do i=1to l;v=rank(substr(n,i,1))-97;a{i}=int(v/9);a{i+l}=mod(int(v/3),3);a{i+l*2}=mod(v,3);end;f='';do i=1to l*3by 3;f=cats(f,byte(a{i}*9+a{i+1}*3+a{i+2}+97));end;f=tranwrd(f,"{"," ");cards;
this is a trifid cipher
test
output
trifidcipher
```
Outputs a dataset containing the output in the variable `f`, along with a bunch of helper variables/array values.
[![enter image description here](https://i.stack.imgur.com/T7dbm.png)](https://i.stack.imgur.com/T7dbm.png)
Ungolfed/explanation:
```
data;
input n : & $99.; /* Read a line of input, maximum 99 characters */
n=tranwrd(trim(n)," ","{"); /* Replace spaces with '{' (this is the ASCII character following 'z', so it makes it easy to do byte conversions, and lets us not have to deal with spaces, which SAS does not like) */
if mod(length(n),3)=0then n=cats(n,'{'); /* If length of n is not coprime with 3, add an extra "space" to the end */
f=n; /* Set output = input, so that the string will have the same length */
l=length(n);    /* Get the length of the input */
array a(999);   /* Array of values to store intermediate results */
do i = 1 to l; /* For each character in the input... */
    v = rank(substr(n,i,1))-97; /* Get the value of the current character, from 0-26 */
    a{i}=int(v/9);          /* Get the table of the current character and store at appropriate index, from 0-2  */
    a{i+l}=mod(int(v/3),3); /* Get the row of the current character, from 0-2 */
    a{i+l*2}=mod(v,3);      /* Get the column of the current character, from 0-2  */
end;
f='';
do i = 1 to l*3 by 3; /* For each character in the output... */
    f=cats(f,byte(a{i}*9+a{i+1}*3+a{i+2}+97)); /* Convert values back from base 3 to base 10, and convert back into ASCII value */
end;
f = tranwrd(f,"{"," "); /* Replaces our "spaces" with actual spaces for final output */
/* Test cases */
cards;
this is a trifid cipher
test
output
trifidcipher
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~146 141 139~~ 136 bytes
I/O is in lowercase.
```
s=>'931'.replace(/./g,d=>Buffer(s.length%3?s:s+0).map(c=>(o=(c>48?c-16:26)/d%3+o*3%27|0,++i)%3?0:(o+97)%123||32),i=o=0).split`\0`.join``
```
[Try it online!](https://tio.run/##bYzLaoQwGIX3fQo3YtI48ZIyFyEO9Dm6MMRE/yH1D0mcle9uhUIXZeCszvnO91BPFXUAn04Ljma3co@yL26iKXgw3iltSMWrqRxl/7laawKJ3JllSnMu7rGLrKb8W3miZU9QEt1/XO/61Jy79kyrMRcM30XeXra6ZAzo8ak7gux2oXnTim0TLS1Bojws0TtIw1c98AfCMgy7xiWiM9zhRCwp0gwxO6KyFMDCmGnwswkFpW//SRPTixrX5NdXw6/vT7f/AA "JavaScript (Node.js) – Try It Online")
### Commented
```
s =>                       // s = input string
  '931'.replace(/./g, d => // for each digit d = 9, 3 and 1:
    Buffer(                //   create a buffer from:
      s.length % 3 ?       //     if the length of s is coprime with 3:
        s                  //       the original input string
      :                    //     else:
        s + 0              //       the input string + an extra '0'
    )                      //
    .map(c =>              //   for each ASCII code c from this Buffer:
      ( o =                //     update o:
        ( c > 48 ?         //       if c is neither a space nor the extra '0':
            c - 16         //         yield c - 16 (which gives 81 .. 106)
          :                //       else:
            26             //         this is the 26th character (space)
        ) / d % 3 +        //       divide by d and apply modulo 3
        o * 3 % 27 | 0,    //       add o * 3, apply modulo 27, coerce to integer
        ++i                //       increment i
      ) % 3 ?              //     if i mod 3 is not equal to 0:
        0                  //       yield 0 (NUL character)
      :                    //     else:
        (o + 97) % 123     //       convert o to the ASCII code of the output letter
        || 32              //       or force 32 (space) for the 26th character
    ),                     //   end of map()
    i = o = 0              //   start with i = o = 0
  ).split`\0`.join``       // end of replace(); remove the NUL characters
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 25 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
g3Öð×«SAð«3L3ã©‡ø˜3ô®Að«‡
```
Since no one posted a 05AB1E answer yet, I figured I'd post my own solution. I see now it's very similar to [*@Dennis♦*' Jelly answer](https://codegolf.stackexchange.com/a/177377/52210), even though I came up with it independently before I posted the challenge.
Input as string, output as a list of characters. Adds one space if the length is divisible by 3.
[Try it online](https://tio.run/##yy9OTMpM/f8/3fjwtMMbDk8/tDrY8fCGQ6uNfYwPLz608lHDwsM7Ts8xPrzl0DqwOFDgv4u916OGOQoaSof3K2kCWTr/80tLCkpLAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVnl4gr2SwqO2SQpK9v/TjQ9PO7zh8PRDq4MdD284tNrYx/jw4kMrHzUsPLzj9Bzjw1sOrQOLAwX@u9h7PWqYo6ChdHi/kiaQpfO/JCOzWAGIEhVKijLTMlMUkjMLMlKLuEpSi0u48ktLCkpLuCAyEAkA).
**Explanation:**
```
g3Ö         # Check if the length of the (implicit) input is divisible by 3
            # (results in 1 for truthy or 0 for falsey)
            #  i.e. "out" → 1
            #  i.e. "test" → 0
   ð×       # Repeat a space that many times
            #  i.e. 1 → " "
            #  i.e. 0 → ""
     «      # And append it to the (implicit) input
            #  i.e. "out" and " " → "out "
            #  i.e. "test" and "" → "test"
      S     # Then make the string a list of characters
            #  i.e. "out " → ["o","u","t"," "]
            #  i.e. "test" → ["t","e","s","t"]
A           # Push the lowercase alphabet
 ð«         # Appended with a space ("abcdefghijklmnopqrstuvwxyz ")
   3L       # Push list [1,2,3]
     3ã     # Cartesian repeated 3 times: [[1,1,1],[1,1,2],...,[3,3,2],[3,3,3]]
       ©    # Save that list of triplets in the registry (without popping)
        ‡   # Transliterate, mapping the letters or space to the triplet at the same index
            #  i.e. ["o","u","t"," "] → [[2,2,3],[3,1,3],[3,1,2],[3,3,3]]
            #  i.e. ["t","e","s","t"] → [[3,1,2],[1,2,2],[3,1,1],[3,1,2]]
ø           # Zip, swapping all rows/columns
            #  i.e. [[2,2,3],[3,1,3],[3,1,2],[3,3,3]] → [[2,3,3,3],[2,1,1,3],[3,3,2,3]]
            #  i.e. [[3,1,2],[1,2,2],[3,1,1],[3,1,2]] → [[3,1,3,3],[1,2,1,1],[2,2,1,2]]
 ˜          # Flatten the list
            #  i.e. [[2,3,3,3],[2,1,1,3],[3,3,2,3]] → [2,3,3,3,2,1,1,3,3,3,2,3]
            #  i.e. [[3,1,3,3],[1,2,1,1],[2,2,1,2]] → [3,1,3,3,1,2,1,1,2,2,1,2]
  3ô        # Split it into parts of size 3
            #  i.e. [2,3,3,3,2,1,1,3,3,3,2,3] → [[2,3,3],[3,2,1],[1,3,3],[3,2,3]]
            #  i.e. [3,1,3,3,1,2,1,1,2,2,1,2] → [[3,1,3],[3,1,2],[1,1,2],[2,1,2]]
®           # Push the triplets from the registry again
 Að«        # Push the lowercase alphabet appended with a space again
    ‡       # Transliterate again, mapping the triplets back to letters (or a space)
            # (and output the result implicitly)
            #  i.e. [[2,3,3],[3,2,1],[1,3,3],[3,2,3]] → ["r","v","i","x"]
            #  i.e. [[3,1,3],[3,1,2],[1,1,2],[2,1,2]] → ["u","t","b","k"]
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 42 bytes
```
;Êv3 ?UpS:U
m!bS=iC)®+27 ì3 ÅÃÕc ò3 £SgXì3
```
[Try it online!](https://ethproductions.github.io/japt/?v=1.4.6&code=O8p2MyA/VXBTOlUKbSFiUz1pQymuKzI3IOwzIMXD1WMg8jMgo1NnWOwz&input=WyJ0IiwiaCIsImkiLCJzIiwiICIsImkiLCJzIiwiICIsImEiLCIgIiwidCIsInIiLCJpIiwiZiIsImkiLCJkIiwiICIsImMiLCJpIiwicCIsImgiLCJlIiwiciJdCi1Q)
The core of this answer comes from a deleted answer by Shaggy, but he never came back to handle inputs of length divisible by 3 so this is a [fixed version](https://ethproductions.github.io/japt/?v=1.4.6&code=O8p2MyA/VXBTOlUKbSFiUz1pQymuKzI3IOwzIMXD1WMg8jMgo1NnWOwz&input=WyJ0IiwiciIsImkiLCJmIiwiaSIsImQiLCJjIiwiaSIsInAiLCJoIiwiZSIsInIiXQotUA==).
Explanation:
```
;                                 #Set C to the string "abcdefghijklmnopqrstuvwxyz"
 Ê                                #Get the length of the input
  v3 ?                            #If it is divisible by 3:
      UpS                         # Add a space
         :U                       #Otherwise don't add a space
                                  #Store the result in U
   S=iC)                          #Set S to C plus a space
m                                 #For each character in U:
 !bS                              # Get the position of that character in S
        ®        Ã                #For each resulting index:
             ì3                   # Convert to base 3
         +27    Å                 # Including leading 0s up to 3 places
                  Õ               #Transpose rows and columns
                   c              #Flatten
                     ò3           #Cut into segments of length 3
                        £         #For each segment:
                           Xì3    # Read it as a base 3 number
                         Sg       # Get the letter from S with that index
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 178 bytes
```
s=>{int[]a={9,3,1},b=(s.Length%3>0?s:s+0).Select(c=>c<97?26:c-97).ToArray();s="";for(int i=0,k,l=b.Length;i<l*3;s+=(char)(k>25?32:97+k))k=a.Sum(p=>b[i%l]/a[i++/l]%3*p);return s;}
```
[Try it online!](https://tio.run/##XY9Na4QwEIbv/RVBEJI161qlFY2J9NJTD4XtTTzEbFyDrkomHsqyv90KW@gHDAw8vO/DjIK9ArO@LqMqwFkznim6b4FaxFfg4mpGV9WSXzOa0McbbTiG8E2PZ9f5iYhKyCGISHjUg1YOKy5UkaVl/JyrfZaS8GN6sVZ@YsKAex5rJ4s3ITI8oj0dePOtYqYYdgmDgGPVSUtwL@KnMonzLA16Qnouw@NywTMXTWX8oT7IygTBYaj9ZDcTZrVb7IiA3Vb28L7d73CLPdcZQNtItL3UmhNSZu609Qj5HdLg/pJpcfPyj90FP/31Cw "C# (Visual C# Interactive Compiler) – Try It Online")
Less golfed... It's still confusing :)
```
// s is an input string
s=>{
  // powers of 3
  int[]a={9,3,1},
  // ensure the length of s is coprime to 3
  // and convert to numbers from 0-26
  b=(s.Length%3>0?s:s+0).Select(c=>c<97?26:c-97).ToArray();
  // reset s to collect result
  s="";
  // main loop
  for(
    // i is the main index variable
    // k is the value of the encoded character
    // l is the length
    int i=0,k,l=b.Length;
    // i continues until it is 3x the length of the string
    i<l*3;
    // convert k to a character and append
    s+=(char)(k>25?32:97+k)
  )
    // compute the trifid
    // (this is the confusing part :)
    k=a.Sum(p=>b[i%l]/a[i++/l]%3*p);
  // return the result
  return s;
}
```
]