[Question]
  [
The problem with the Caesar cipher is the resulting words are often unpronounceable. The problem with Pig Latin is that it is easy to decode. Why not combine them? 
**Input**
A word consisting of the 26 english letters. 
**Output** 
First, change every consonant in the word to the next consonant in the alphabet. So, b goes to c, d goes to f, and z goes to b. Then, change every vowel to the next vowel in the alphabet (u goes to a). Last, only if the first letter of the word is a consonant, move that letter to the end of the word and add "ay" to the end of the word. 
Examples:
```
cat -> evday  
dog -> uhfay   
eel -> iim
```
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code wins.
* Case does not matter.
* Vowels that will be used are A, E, I, O, and U
  
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~96~~ 69 bytes
```
->s{/^[^aeiou]/=~(r=s.tr'zb-yadehinotu','b-zefijopuva')?$'+$&+'ay':r}
```
[Try it online!](https://tio.run/##DcrdDoIgGADQe5/CC9dXE/W@jXoQhttHgtFKGEIDf3p18uZcHRdEyorm5javXc96lNoE3tHf2dG59Q4W0SQc5FNPxgcgIJpFKv0yNnwRLvcK6upUAya4uj0zeKA/0mDGQynfQEoQYQTeftCuW9wKW7JIFIuc70X@Aw "Ruby – Try It Online")
Fun fact of the day: tr() matches strings right-to-left. I always assumed it was left-to-right.
[Answer]
# [R](https://www.r-project.org/), ~~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](https://codegolf.stackexchange.com/a/172313/81549) translation strings - upvote it!
```
function(s)sub("^([^aeiou])(.*)","\\2\\1ay",chartr('zb-yadehinotu','b-zefijopuva',s))
```
[Try it online!](https://tio.run/##JcZLDsIgEADQvceYDTMGTOram4hNBgotxjCGj0l7eTTxrV4Z8WZG7Nm3JBkr1e4QZrzPHJL0B@HlTKDB2qu1E@@g/calFVSHMzsvYUtZWldaOXOEmJ7y7h9WuhKNiOC5AZ1@WWT9J4QX0PgC "R – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 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!](https://tio.run/##TY9Lb8IwEITv/IqVJSS7CVY59EIaql56q3rgiHpwnAcOiZN6NykU5beneVDowVqPZvbTTq5atcrjY2/KunIE@aBlQ6aQaWM1mcrKh2ChC4UI78pYuCwA6iYqjAYkRcNoKxNDOXh8R87YbP8JymUopijA25XzPLv@PLaQQtjjanuZNbiQMV@FTCWmalSk4zQ75MeitPWXQ2q/T@efiPk6RIl1YYgzJvaPnwGGShobJ6ePlGuxfXoZ/CbCicnXwtMea05sg0FaOd4qB/HmH0E4b9jXB@Veid9BsfDWInAJNc6CC7o@mJrc6lGChBBeCwIwrYj5fyKusrtIkoJN/25mjGdcG4@UzcwSN9TujJSUsmpI1kOKUs6WuIElLi3zp7APqVR1XZz5qISYud1ifF3/Cw "Java (JDK) – Try It Online")
## Credits
* -7 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen), using better types.
* -1 byte thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 21 bytes
```
žMDÀ‡žNDÀ‡¬žNsåiÀ…ÿay
```
[Try it online!](https://tio.run/##yy9OTMpM/V9TVvn/6D5fl8MNjxoWHt3nB2EcWgNkFh9emgniLTu8P7Hyf22l0uH9Crp2Cof3K@n8T04s4UrJT@dKTc0BAA "05AB1E – Try It Online")
**Explanation**
```
žMDÀ‡                   # replace each vowel with the next vowel in the alphabet
     žNDÀ‡              # replace each consonant with the next consonant in the alphabet
          ¬žNsåi        # if the first letter is a consonant
                À…ÿay   # rotate the word left and add "ay"
```
[Answer]
# T-SQL, 169 bytes
```
SELECT IIF(CHARINDEX(LEFT(a,1),'aeiou')=0,SUBSTRING(a,2,99)+LEFT(a,1)+'ay',a)FROM
(SELECT TRANSLATE(v,'aeioubcdfghjklmnpqrstvwxyz','eiouacdfghjklmnpqrstvwxyzb')a FROM t)s
```
Input is via a pre-existing table, [per our IO standards](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/5341#5341).
Performs the characters substitution first, using the ([new to SQL 2017](https://docs.microsoft.com/en-us/sql/t-sql/functions/translate-transact-sql?view=sql-server-2017)) `TRANSLATE` function, then checks the first character.
Annoying long mostly due to SQL keyword length.
[Answer]
# [Node.js 10.9.0](https://nodejs.org), ~~121~~ 116 bytes
Expects the input string in lower case.
```
s=>(v=n=>2130466>>n&1)((a=Buffer(s).map(n=>(g=i=>v(n=n%61?n+1:97)^i?g(i):n)(v(n))))[0],a+='')?a:a.slice(1)+a[0]+'ay'
```
[Try it online!](https://tio.run/##bYpRC8IgFEbf@xmD8l6sMSsWDXTQ34iCy1IxTMdcg369@Rx9T4dzvictlIbJjfMuxIfORuYkFSwySLUXh@bYtkqFjUAAkpe3MXqChPWLRigPsNJJtRQM61b0gYvufMK76y047AJCSVh2bW5b4pIx7KmjOnk3aBDIqQTO6MPyEEOKXtc@WjBQDTRXiKsf@4j2j9XaF5u/ "JavaScript (Node.js) – Try It Online")
### Identifying vowels
To identify vowels, the helper function \$v\$ uses the following bitmask:
```
2130466 = 000001000001000001000100010
               ^     ^     ^   ^   ^
          zyxwvutsrqponmlkjihgfedcba-
```
And does:
```
(2130466 >> n) & 1
```
We don't need to mask out the relevant bits of \$n\$, because it is done implicitly. Below is the relevant quote from [the ECMAScript specification](https://www.ecma-international.org/ecma-262/9.0/index.html#sec-signed-right-shift-operator): 
> 
> Let *shiftCount* be the result of masking out all but the least significant 5 bits of *rnum*, that is, compute *rnum* & 0x1F.
> 
> 
> 
### Commented
```
s =>                      // s = input string
  ( v = n =>              // v = helper function taking n = ASCII code in [97..122]
    2130466 >> n & 1      //     and returning 1 if the corresponding character is a vowel
  )                       //     or 0 otherwise (see the previous paragraph)
  (                       // this statement will ultimately invoke v on a[0]
    ( a = Buffer(s)       //   convert s to a Buffer, holding ASCII codes
      .map(n =>           //   for each ASCII code n in there:
        ( g = i =>        //     g = recursive function taking i = vowel flag
          v(              //       update n and invoke v on the new value:
            n = n % 61 ?  //         if n is less than 122 (meaning less than 'z'):
              n + 1       //           increment n
            :             //         else:
              97          //           wrap around by setting n to 97 (meaning 'a')
          ) ^ i ?         //       if v(n) is not equal to i:
            g(i)          //         do recursive calls until it is
          :               //       else:
            n             //         stop recursion and return the new n
        )(v(n))           //     initial call to g with i = v(n)
      )                   //   end of map()
    )[0],                 //   invoke v on a[0]
    a += ''               //   coerce the updated Buffer back to a string
  ) ?                     // if a[0] is a vowel:
    a                     //   return the string as-is
  :                       // else:
    a.slice(1) + a[0]     //   move the leading consonant to the end
    + 'ay'                //   and append the 'ay' suffix
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~153~~ ~~121~~ ~~110~~ ~~99~~ 91 bytes
```
lambda s:[s[1:]+s[0]+"ux",s][s[0]in'aeiou'].translate(8*".ecdfighjoklmnpuqrstvawxyzb.....")
```
[Try it online!](https://tio.run/##HcdBDoIwEEDRtZyi6WZAGqKuDAlepHYxQIFqaZEpClwexb94yR@W0Hl32ZrivlnsyxoZ5ZLkOVcpyZNK@TRzQUruYxygNn4ClYURHVkMOr4eeaarujFt9/BP27theo0U3viZl7XM9niyNX5kxIxjEioMIKD27U@tLQgG6x/cnWZQeXQYRuMCIwHFDUQTUxJtXw "Python 2 – Try It Online")
8 bytes shaved off due to a suggestion by [Matthew Jensen](https://codegolf.stackexchange.com/users/87728/matthew-jensen)
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 20 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ù≥±╘├*Lâ■8O±âΓ║Θæ%º•
```
[Run and debug it](https://staxlang.xyz/#p=97f2f1d4c32a4c83fe384ff183e2bae99125a707&i=cat%0Adog%0Aeel%0Az%0Athe&m=2)
**Explanation**
```
Vc:tVv:tBcVc#{sL"ay"+}ML             #Full program, unpacked, implicit input
Vc:t                                 #Push consonants and ring translate input
    Vv:t                             #Push vowels and ring translate input
        BCvc#                        #Push first letter and tail of word, find number 
                                     #of occurrences to consonants
             {sL"ay"+}M              #If truthy (word starts with consonant)
                                     #swap stack, listify, add "ay"
                       L             #Listify stack (combines words that start with vowel)
```
I went through a few iterations and finally got it down to 20. My original solution was 53 bytes.
[Answer]
# Shell script, 70 bytes
```
tr a-z b-{|tr eiou{bfjpv fjpvbeioua|sed -E 's/^([^aeiou])(.*)/\2\1ay/'
```
[Try it online!](https://tio.run/##S0oszvj/v6RIIVG3SiFJt7oGyEzNzC@tTkrLKihTABFJIH5iTXFqioKuq4J6sX6cRnRcIkgwVlNDT0tTP8YoxjCxUl/9//@M1JycfIXy/KKcFAA "Bash – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 102 97 bytes
```
h(c:r)|elem c"aeiou"=c:r|True=r++c:"ay"
f s=h["ecdfighjoklmnpuqrstvawxyzb"!!(fromEnum y-97)|y<-s]
```
[Try it online!](https://tio.run/##Ncw7D4IwFAXgnV9RbxwgDbORWDc3N92MQy0XivSBfagQ/jt2kO3LyTlHct@jUssic1G5YkaFmgjg2NkILEXz1UVkjlJRAR8ha4hn8gYo6qZr5dP2SpshvpwPb/75jtMDNpu8cVafTNRkLPe7Yh4Ppb8vLpq0HWK4BHc2W08pkPJIgNL0mWneGVbbjJDUA8ED/FnbdiWiWhkkrpxg@QE "Haskell – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 50 bytes
```
T`uo`aei\oub-df-hj-np-tv-zb
^([^aeiou])(.*)
$2$1ay
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wPyShND8hMTUzJr80STclTTcjSzevQLekTLcqiStOIzoOKJVfGqupoaelyaVipGKYWPn/f3JiCVdKfjpXamoOAA "Retina 0.8.2 – Try It Online") Link includes test cases. Similar approach to the R answer. Explanation:
```
T`uo`aei\oub-df-hj-np-tv-zb
```
`o` refers to the other set, i.e. `aei\oub-df-hj-np-tv-zb`, which expands to `aeioubcdfghjlkmnpqrstvwxyzb`, so `uo` expands to `uaeioubcdfghjlkmnpqrstvwxyzb`. This results in the following transliteration:
```
uaeioubcdfghjlkmnpqrstvwxyzb
aeioubcdfghjlkmnpqrstvwxyzb
```
The second `u` and `b` are ignored as they can never be matched, so this provides the desired cipher. (Note that in Retina 1 you can of course use `v` instead of `aei\ou` for a 5 byte saving.)
```
^([^aeiou])(.*)
$2$1ay
```
If the first letter is not a vowel, rotate it to the end and suffix `ay`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 24 bytes
```
,ṙ¥1y
ØẹçØḄçṙḢe©ØḄƊ®⁾ayx
```
[Try it online!](https://tio.run/##y0rNyan8/1/n4c6Zh5YaVnIdnvFw187Dy4HUjpbDy4GiD3csSj20Esw/1nVo3aPGfYmVFf///0/JTwcA "Jelly – Try It Online")
Saved 1 byte thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan) (use the two-char syntax rather than quotes).
[Answer]
# [><>](https://esolangs.org/wiki/Fish), ~~94~~ 92 bytes
```
i:0(?v"a"%
2%?!v\~r:5g
a2r}<vr+ad*
ol?!;>4g
ecdfighjoklmnpuqrstvawxyzb
1   1   1     1     1
```
[Try it online!](https://tio.run/##S8sszvj/P9PKQMO@TClRSZXLSNVesSymrsjKNJ0r0aio1qasSDsxRYsrP8de0drOJJ0rNTklLTM9Iys/Oyc3r6C0sKi4pCyxvKKyKonLUEFBAYbh5P//qak5AA "><> – Try It Online")
*Edit: Saved 2 bytes by taking input mod 97 rather than 32, so the dictionary could start at the beginning of the line. Previous version:*
```
i:0(?v84*%
2%?!v\~r:5g
37r}<vr*46*
ol?!;>4g
 ecdfighjoklmnpuqrstvawxyzb
 1   1   1     1     1
```
[Answer]
# [Red](http://www.red-lang.org), 149 bytes
```
func[s][c:"aeioua.bcdfghjklmnpqrstvwxyzb"t: copy""foreach p s[append t c/(1
+ index? find c p)]if 7 < index? find c t/1[move t tail t append t"ay"]t]
```
[Try it online!](https://tio.run/##XYxBCsIwEEX3PcUwK0WwdCUUwTu4DVmkk0kbbZOYprX18rEbRVw93of3I@t8ZS1kYepsJkdilIJqVGz9pI4NadN2t3s/uPCIY5qfy/pqMNVAPqyIxkdW1EGAUagQ2GlIQOWuKg5gneblAmYjEIS9tAZOcP7bU1mJwc@8dUnZfsPnB9WKMskconUJDCCphMXXtG9/jLnHIr8B "Red – Try It Online")
As (almost) always, the longest entry
[Answer]
# [F# (Mono)](http://www.mono-project.com/), 197 bytes
```
let f(s:string)=
 let a="aeiouabcdfghjklmnpqrstvwxyzb"
 new string(s|>Seq.map(fun c->a.[a.IndexOf(c)+1])|>Seq.toArray)|>(fun x->if a.IndexOf(x.[0])>5 then x.Substring(1)+(string x.[0])+"ay"else x)
```
[Try it online!](https://tio.run/##RY3NaoQwFIX3PsUlMJAghs6imxYDXRYKXcxSXES9cTLVxEliJ5Z5d5vRQjf373z3HOWL0Rq7rgMGUNS/@OC06VmZweMiSyJR21k2baf68@VrGM10dT583@Ly05AMDN5g/6H@Lk545aOcqJoNtIWQvJL83XQYPxVtWX6s2c4E@@acXNK2obEQWsE/Gnn1VDPxDOGMSeWnufnLOLKc7iPsUE7kQnDwCJFla0VaGcgr6WyfKuJAargL@NA@cB3QwRaXDKAQMCWboAyQg4dSwMGTTaHq0RhbfwE "F# (Mono) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 56 bytes
```
y/a-z/ecdfighjok-npuq-tvaw-zb/;s/^([^aeiou])(.*)/$2$1ay/
```
[Try it online!](https://tio.run/##BcFBDkBADADAu3c4IKmGxMlThKQoFtFlF@HxasbysRaqDxK8yF0/mHGaZYHNnjv4i254WywdNlHVEBs56zhKkxjDPMzoQdWOfNDLGDCvn1hvZHMK9gc "Perl 5 – Try It Online")
[Answer]
# [JavaScript (SpiderMonkey)](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/45), 107 bytes
```
x=>x.replace(/./g,y=>(z='aeiouabcdfghjklmnpqrstvwxyzb')[z.search(y)+1]).replace(/^([^aeiou])(.+)/,'$2$1ay')
```
[Try it online!](https://tio.run/##bcxLCoMwFEDReZchQvLQRuxcNyIKMT7jJ5o0sda4@bR0UiidHrh34jt3wo5muzozdmgXvc7oQ1@EoygPZtEoLpBmLJOpL0p6FoTjqB@8FV0vh2lWy2ru1m378/BnS6A6mUNuxUA9JHkN30VDq@bT1kBZAllK4lucc08gCL06rZApLWlPI8G3CODyo52WfxRRvTW8AA "JavaScript (SpiderMonkey) – Try It Online")
Expects input in lowercase.
Replaces each character of the string with a the one after it in the string `'aeiouabcdfghjklmnpqrstvwxyzb'`, and then piglatinifies anything with an initial consonant.
[Answer]
# PHP, 112 bytes
```
<?=strtr(($s=strstr(aeiou,($s=$argn)[0])?$s:substr($s,1).$s[0].ux),join(range(a,z)),ecdfighjoklmnpuqrstvawxyzb);
```
or
```
<?=strtr(($s=strstr(aeiou,($argn)[0])?$argn:substr($s,1).$s[0].ux),join(range(a,z)),ecdfighjoklmnpuqrstvawxyzb);
```
assume lower case input. Run as pipe with `-nR` or [try them online](http://sandbox.onlinephpfunctions.com/code/d0f21a36cfe3f98e069799d069c4183eb4d1b2ca).
---
You could as well use  
`strtr($s,uzbcadfgehjklminpqrsotvwxy,range(a,z))` instead of  
`strtr($s,range(a,z),ecdfighjoklmnpuqrstvawxyzb)`.
[Answer]
# Dyalog APL (SBCS), 57 bytes
```
{a←⎕A{(⍺~⍵)⍵}'AEIOU'⋄('AY',⍨1⌽⊢)⍣(∊/⊃¨⍵a)⊢(⊂⍵⍳⍨∊a)⌷∊1⌽¨a}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///303hUdsEhepEIPmob6pjtcaj3l11j3q3agJxrbqjq6d/qLrCo@4WBQ11x0h1nUe9Kwwf9ex91LUIqGCxxqOOLv1HXc2HVgBVKyRqAoU1HnU1ATmPejcDlQKlgYI924E0SNehFYm1XEBbwFa6HVqhoO7sGKKuoO7i7w4kXV19gGSIh6v6//8A "APL (Dyalog Unicode) – Try It Online")
Takes input in uppercase only! (Because `⎕A` is uppercase alphabet)
* `⎕A{(⍺~⍵)⍵}'AEIOU'`: Vector of consonants and vowels
* `(⊂⍵⍳⍨∊a)⌷∊1⌽¨a`: Uses indices of each letter of the word in the normal alphabet (`⊂⍵⍳⍨∊a`) to index (`⌷`) into the cipher `∊1⌽¨a`.
* `('AY',⍨1⌽⊢)⍣(∊/⊃¨⍵a)`: Moves first letter to the end and appends 'AY', if the first letter is a consonant.
Thanks for the cool challenge!
[Answer]
# [Lexurgy](https://www.lexurgy.com/sc), 202 bytes
```
class C {b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} 
class V {a,e,i,o,u}
c:
{@C,@V}=>{{c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z,b},{e,i,o,u,a}}
p:
([]+)$1 *=>$1/$ @V _
(@C+)$1 ([]*)$2=>$2 $1 ay/$ _
```
]