# Created by 🦄Uni🦄 """ Input instructions: 1) Do you wish to encrypt or decrypt? (write encrypt or decrypt, followed by the shift spaced) and press Enter. 2) Input your message and press Submit. Input example: Input: encrypt 1 a, cF b. Output: ---------- |b, dG c.| ---------- """ #If you have any suggestions about the input method feel free to drop them in the comments def encrypt_caesar(x,a): res=0 #int cr='' if not x.isalpha(): return x else: if x.isupper(): res=ord(x)-ord('A') #0<=res<=25 s=(res+a)%26 cr=chr(s+ord('A')) else: res=ord(x)-ord('a') #0<=res<=25 s=(res+a)%26 cr=chr(s+ord('a')) return cr def decrypt_caesar(y,b): res=0 #int cr='' if not y.isalpha(): return y else: if y.isupper(): res=ord(y)-ord('A') #0<=res<=25 s=(res-b)%26 cr=chr(s+ord('A')) else: res=ord(y)-ord('a') #0<=res<=25 s=(res-b)%26 cr=chr(s+ord('a')) return cr te=[] dec=input().split(" ") if "encrypt" in dec or "decrypt" in dec: if len(dec)==1: print("The shift key must be a positive integer.") elif type(int(dec[1]))==int: message=input() if dec[0].lower()=='encrypt': for char in list(message): te.append(encrypt_caesar(char,int(dec[1]))) else: for i in list(message): te.append(decrypt_caesar(i,int(dec[1]))) te=''.join(te) print('-'*(len(te)+2)+'\n'+'|'+te+'|'+'\n'+'-'*(len(te)+2)) else: print("The shift key must be a positive integer.") else: print("Please specify if you want to encrypt or decrypt your message.")
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