Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Last active July 20, 2017 21:59
Show Gist options
  • Save kylelemons/50732e76a206e4222b2be30c289a0194 to your computer and use it in GitHub Desktop.
Save kylelemons/50732e76a206e4222b2be30c289a0194 to your computer and use it in GitHub Desktop.
$ /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