hamsterman: Good eye. I hadn't considered interactions between a and cipher. Actually, the same happens for cipher=3. This is because 3 is a divisor of 27. When cipher=9 it's even worse. All letters map to one of {0,9,18}.
So yeah. Bad idea to mix multiplication and modulo by a non-prime.