I'm pretty sure that the Professor would have been quite good at it, but I do not think he could have achieved the results of Mr. Turing, who is somewhat distastefully - in my opinion - called the "gay codebreaker". I think Tolkien lacked the analytical, computer-like way of thinking that was necessary, and perhaps this is why we refused... not wanting to turn into some kind of a "machine".
Now don't get me wrong, he was a really smart guy, but not really the type for this kind of job. Had the secret messages been hidden in riddles and poems, then he would have surely accepted.