#ceasar cipher import pyperclip #the string to be encrypted or decrypted message = 'this is my secret message.' #the encryption or decryption key key = 13 #tells the program to decrypt or encrypt mode = 'encrypt' #set to encrypt or decrypt #every possible symbol that can be encrypted LETTERS = 'ABCDEFGHIJkLMNOPQRSTUVWXYZ' #stores the enc/dec for of the message translated = '' #capitilize the string in message message = message.upper() #run the enc/dec code on each symbol in the message string for symbol in message: if symbol in LETTERS: #get the enc/dec number for this symbol num = LETTERS.find(symbol) #get the number of the symbol if mode == 'encrypt': num = num + key elif mode == 'decrypt': num = num - key #handle the wrap around if num is larger than the length of LETTERS or less than 0 if num >= len(LETTERS): num = num - len(LETTERS) elif num < 0: num = num + len(LETTERS) #add enc/dec numbers symbol at the end of the translated translated = translated + LETTERS[num] else: #just add the symbol without enc/dec it translated = translated + symbol print(translated) pyperclip.copy(translated)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question