""" Name: ROT13 Purpose: Encode/decode text strings using the ROT13 Caesar cipher Features: - Encodes//descoes text strings using the ROT13 Caesar cipher - Preserves punctuation, digits, and whitespace Examples: print ROT13('Hello!') --> 'Uryyb!' print ROT13('Hello there!') --> 'Uryyb gurer!' print ROT13('I am 10 years old') --> 'V nz 10 lrnef byq' print ROT13("How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.") -->'Ubj pna lbh gryy na rkgebireg sebz na vagebireg ng AFN? In the elevators, the extrovert looks at the OTHER guy's shoes.' print ROT13(ROT13('Hello there!')) --> 'Hello there!' See more at: http://pythonfiddle.com/rot-caesar-cipher#sthash.hs1VEB6w.dpuf """ inList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' outList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' converstionDict = dict(zip(inList,outList)) def ROT13 (s): outList = [] outString = '' for letter in s: if letter in inList: outList.append(converstionDict[letter]) else: outList.append(letter) outString = outString.join(outList) return outString print ROT13('Hello!') print ROT13('Hello there!') print ROT13('I am 10 years old') print ROT13("How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.") print ROT13(ROT13('Hello there!'))
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