Created
July 21, 2015 13:44
-
-
Save bdkosher/a6aa46252c8e85747771 to your computer and use it in GitHub Desktop.
A Groovy script for applying a shift cipher to some text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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