Last active
July 20, 2017 21:59
-
-
Save kylelemons/50732e76a206e4222b2be30c289a0194 to your computer and use it in GitHub Desktop.
This file contains 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
$ /usr/bin/python3.4 | |
Python 3.4.3 (default, Nov 17 2016, 01:08:31) | |
[GCC 4.8.4] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> letters = 'abcdefghijklmnopqrstuvwxyz' | |
>>> shift = lambda s, d: s[d:]+s[:d] | |
>>> trans = lambda d: shift(letters.lower(), d)+shift(letters.upper(), d) | |
>>> encrypt = lambda s, d: s.translate(str.maketrans(trans(0), trans(d))) | |
>>> decrypt = lambda s, d: encrypt(s, -d) | |
>>> encrypt('You cracked the code!', 14) | |
'Mci qfoqysr hvs qcrs!' | |
>>> decrypt('Mci qfoqysr hvs qcrs!', 14) | |
'You cracked the code!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment