RosettaCodeData/Task/Caesar-cipher/Groovy/caesar-cipher-4.groovy
2015-02-20 00:35:01 -05:00

4 lines
189 B
Groovy

def caesarEncode(k, text) {
text.tr('a-zA-Z', ((('a'..'z')*2)[k..(k+25)] + (('A'..'Z')*2)[k..(k+25)]).join())
}
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }