def CaesarCiper(str_,DeEn, key):
a_=[]
for i in str_:
if(DeEn == "D"):
a_.append(ord(i) - key)
else:
a_.append(ord(i) + key)
def_=""
for j in a_:
def_ = def_ + chr(j)
return def_
>>> a = CaesarCiper("This is a test with long sentence for Decode/Encode the message","E",2)
>>> a
'Vjku"ku"c"vguv"ykvj"nqpi"ugpvgpeg"hqt"Fgeqfg1Gpeqfg"vjg"oguucig'
>>> b = CaesarCiper(a,"D",2)
>>> b
'This is a test with long sentence for Decode/Encode the message'
No comments:
Post a Comment