# Caesar
class Caesar:
def encryption(self,x,num1):
li = [chr(i) for i in range(65,91)]
ls = [chr(i) for i in range(97,123)]
li1 = []
for i in x:
if i in ls and num1 <= 25:
s = ls.index(i)
if s+num1 >= len(ls[s:]):
li1.append(ls[num1-len(ls[s:])])
else:
li1.append(ls[s+num1])
elif i in li and num1 <= 25:
s1 = li.index(i)
if s1+num1 > len(li[s1:]):
li1.append(li[num1-len(li[s1:])])
else:
li1.append(li[s1+num1])
else:
li1.append(i)
if len(li1) > 0:
return ''.join(li1)
return x
解密函数
# decrypt
def decrypt(self,x,num1):
li = [chr(i) for i in range(65,91)]
ls = [chr(i) for i in range(97,123)]
li1 = []
for i in x:
if i in ls and num1 <= 25:
s = ls.index(i)
li1.append(ls[s+(-num1)])
elif i in li and num1 <= 25:
s1 = li.index(i)
li1.append(li[s1+(-num1)])
if len(li1) > 0:
return ''.join(li1)
return x