#!/bin/python ''' Caesar Cipher here inclusive of basic punctuation where. a to z = 1 to 26 space = 27 comma = 28 period = 29 You can also decode a message by making your key its negative equivalent upon input. By smartgrowthsolutions.com.au on the 22/03/2014 ''' from collections import deque as numbers from string import ascii_lowercase as alphabet def rosetta_stone(key): r = numbers(range(1,30)) r.rotate(key) r = list(r) return dict(zip(alphabet + ' ' + ',' + '.',r)) def enumerate(message, key): output = [] code = [] cipher = rosetta_stone(key) for character in message: for key, value in cipher.items(): if character is key: output.append(value) return output def encode(message, key): output = [] code = enumerate(message, key) r = rosetta_stone(0) for number in code: for key, value in r.items(): if number is value: output.append(key) return output message = raw_input('Message: ') key = int(raw_input('Key: ')) encoded_message = ''.join(encode(message, key)) print 'Your code is:', encoded_message print 'Your key was: ', key
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