alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" ," "] cypher_alpha = [] def encode(message,cypher_alpha,alpha): coded_message = [] for i in range(len(message)): for j in range(len(alpha)): if message[i] == alpha[j]: coded_message.append(cypher_alpha[j]) cypher_alpha.append(cypher_alpha.pop(0)) return coded_message def decode(message,cypher_alpha,alpha): decoded_message = [] for i in range(len(message)): for j in range(len(cypher_alpha)): if message[i] == cypher_alpha[j]: decoded_message.append(alpha[j]) cypher_alpha.append(cypher_alpha.pop(0)) return decoded_message while True: keyword = raw_input("Enter you Keyword:\n") key = [] for i in keyword: if i not in key: key.append(i) for i in key: cypher_alpha.append(i) for i in alpha: if i not in cypher_alpha: cypher_alpha.append(i) message = raw_input("Enter your message:\n") encrypt = raw_input("encode or decode?\n") if encrypt == "encode": coded_message = encode(message,cypher_alpha,alpha) elif encrypt == "decode": coded_message = decode(message,cypher_alpha,alpha) coded_message = "".join(coded_message) print coded_message repeat = raw_input("repeat?\n") if repeat == "no": break
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