Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created July 21, 2015 13:44
Show Gist options
  • Select an option

  • Save bdkosher/a6aa46252c8e85747771 to your computer and use it in GitHub Desktop.

Select an option

Save bdkosher/a6aa46252c8e85747771 to your computer and use it in GitHub Desktop.
A Groovy script for applying a shift cipher to some text
String shiftCipher(String text, int amt = -3) {
new String(text.toUpperCase().chars.collect { c ->
c < 33 ? c : (c - 65 + (amt < 0 ? 26 + amt : amt)) % 26 + 65
} as char[])
}
(-25..25).each { amt -> println "$amt: ${shiftCipher('WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ', amt)}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment