import pyperclip
message='This is my secret message.'
key=13
mode='encrypt'
LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
translated=''
message=message.upper()
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 mode<0:
num=num+len(LETTERS)
translated=translated+LETTERS[num]
else:
transted=translated+symbol
print(translated)
pyperclip.copy(translated)
以上是加密,现在解密:
注释:mode为encrypt时为加密,为decrypt时则为解密。
import pyperclip
message='GUVFVFZLFRPERGZRFFNTR'
key=13
mode='decrypt'
LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
translated=''
message=message.upper()
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 mode<0:
num=num+len(LETTERS)
translated=translated+LETTERS[num]
else:
transted=translated+symbol
print(translated)
pyperclip.copy(translated)