#凯撒加密
message ="i will play basketball this afternoon"
key =12
mode ='encrypt'#encrypt表示加 decrypt表示减
LETTERS ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
message = message.upper()
result=''for symbol in message:if symbol in LETTERS:
num = LETTERS.find(symbol)if mode =='encrypt':
num = num + key
elif mode =='decrypt':
num = num - key
if num>=len(LETTERS):
num = num -len(LETTERS)
elif num <0:
num = num +len(LETTERS)
result = result + LETTERS[num]else:
result += symbol
print(result)
#暴力破译凯撒加密
for i in range(len(LETTERS)):
translate =''for symbol in result:if symbol in LETTERS:
num = LETTERS.find(symbol)
num = num - i
if num <0:
num = num +len(LETTERS)
translate = translate + LETTERS[num]else:
translate = translate + symbol
print('key #%s : %s'%(i,translate))
注:本模块完全是个人兴趣#凯撒加密message = "i will play basketball this afternoon"key = 12mode = 'encrypt'#encrypt表示加 decrypt表示减LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"message = message.upper()result= ''for symbol in message: if symbol in LETTERS: nu