def decode(text, shift):
d = {}
for c in (65, 97):
for i in range(26):
d[chr(i+c)] = chr((i+shift) % 26 + c)
return "".join([d.get(c, c) for c in text])
The eagle eyed will recognise this from the import this
source code. I always thought it was a neat way of doing rot(x) encoding.
edit: this takes into account capital letters too, if you didn't want that then you could reduce it to:
def decode(text, shift):
d = {}
for i in range(26):
d[chr(i+97)] = chr((i+shift) % 26 + 97)
return "".join([d.get(c, c) for c in text])