2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -4,16 +4,16 @@ def encrypt(message, key):
|
|||
|
||||
# convert to uppercase.
|
||||
# strip out non-alpha characters.
|
||||
message = filter(lambda _: _.isalpha(), message.upper())
|
||||
message = filter(str.isalpha, message.upper())
|
||||
|
||||
# single letter encrpytion.
|
||||
def enc(c,k): return chr(((ord(k) + ord(c)) % 26) + ord('A'))
|
||||
def enc(c,k): return chr(((ord(k) + ord(c) - 2*ord('A')) % 26) + ord('A'))
|
||||
|
||||
return "".join(starmap(enc, zip(message, cycle(key))))
|
||||
|
||||
def decrypt(message, key):
|
||||
|
||||
# single letter decryption.
|
||||
def dec(c,k): return chr(((ord(c) - ord(k)) % 26) + ord('A'))
|
||||
def dec(c,k): return chr(((ord(c) - ord(k) - 2*ord('A')) % 26) + ord('A'))
|
||||
|
||||
return "".join(starmap(dec, zip(message, cycle(key))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue