the-honk/school/a-level/Y12 2022-2024/Algorithms/caesar.py

10 lines
352 B
Python
Raw Normal View History

2024-10-09 17:02:48 +00:00
# def encode(text: str, key: int) -> str:
# return ''.join(chr(ord(c) + (key % 26)) for c in text)
# def decode(ciphertext: str, key: int) -> str:
# return ''.join(chr(ord(c) - (key % 26)) for c in ciphertext)
c,o,e,d=chr,ord,lambda t,k:''.join(c(o(x)+k%26)for x in t),lambda t,k:''.join(c(o(x)-k%26)for x in t)
print(e("cats", 6))