The Improved Caesar Pig Latin Cipher
Ruby, 96 69 bytes
->s{/^[^aeiou]/=~(r=s.tr'zb-yadehinotu','b-zefijopuva')?$'+$&+'ay':r}
Try it online!
Fun fact of the day: tr() matches strings right-to-left. I always assumed it was left-to-right.
R, 86 85 bytes
Simple way. chartr
has the charming and useful property that it can specify letter ranges, which save a few bytes.
-1 bytes by stealing @GB's Ruby solution's translation strings - upvote it!
function(s)sub("^([^aeiou])(.*)","\\2\\1ay",chartr('zb-yadehinotu','b-zefijopuva',s))
Try it online!
Java (JDK), 167 bytes
s->{String r="",a="aeiouabcdfghjklmnpqrstvwxyzb",c=s.split("")[0];s=a.indexOf(c)>5?s.substring(1)+c+"ux":s;for(var d:s.split(""))r+=a.charAt(a.indexOf(d)+1);return r;}
Try it online!
Credits
- -7 bytes thanks to Kevin Cruijssen, using better types.
- -1 byte thanks to ceilingcat.