This function is like the magic decoder rings you used to find in cereal boxes. It makes a simple substitution of letters found in the code string for letters in the same relative position in the alphabet.
A space is expected as the last character but may be placed anywhere. If placed in position 5 for example any spaces in the original text would be replaced with “e”.
MagicEncoder (theText;theCode)
// Note that there is a space in the last character position of "alpha".
// This function does not preserve upper case characters.
Let ( alpha = "abcdefghijklmnopqrstuvwxyz " ;
If ( Length ( theText ) > 1;
Middle ( theCode ; Position ( alpha ; Middle ( theText ; 1 ; 1 ) ; 1 ; 1 ) ; 1 ) & MagicEncoder ( Right ( theText; Length ( theText ) - 1 ); theCode );
Middle ( theCode ; Position ( alpha ; theText ; 1; 1 ) ; 1 )
)
)
