#!/usr/bin/python3 def encode(): alphabet=list('abcdefghijklmnopqrstuvwxyz') raw_txt=input("Please enter the string you want to encode\n") offset=input("Please enter a + or - followed by the number you want to offset by\n") offset=int(offset) encoded_txt='' for char in raw_txt: try: temp_char=alphabet.index(char)+offset encoded_txt+=alphabet[temp_char] except ValueError: encoded_txt+=char return encoded_txt def decode(encoded_txt): alphabet=list('abcdefghijklmnopqrstuvwxyz') offset=input("Please enter a + or - followed by the offset\n") offset=int(offset) decoded_txt='' for char in encoded_txt: try:temp_char=alphabet.index(char)-offset decoded_txt+=alphabet[temp_char] except ValueError: decoded_txt+=char return decoded_txt print(encode()) print(decode())
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