Created
October 16, 2017 20:06
-
-
Save snahor/db8e2c2914dc9a108541eedca56c57b3 to your computer and use it in GitHub Desktop.
Caesar Cipher
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
from functools import wraps | |
a_ord = ord('a') | |
class NonAlphaException(Exception): | |
pass | |
def check(func): | |
@wraps(func) | |
def wrapper(alpha, offset): | |
if not alpha.isalpha(): | |
raise NonAlphaException | |
return func(alpha, offset) | |
return wrapper | |
@check | |
def encrypt(alpha, offset): | |
return chr(a_ord + ((ord(alpha) - a_ord + offset) % 26)) | |
@check | |
def decrypt(alpha, offset): | |
return chr(a_ord + ((ord(alpha) - a_ord - offset) % 26)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment