The function appears to work correctly for all input words I've tested so far. However, there may be certain input words that do not follow the substitution rule and result in an undefined output.

Please provide more input words for me to test.