Download code

Jump to: navigation, search

Back to Rot13_(Python)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

rot13.py

 1 #!/usr/bin/env python
 2 # The authors of this work have released all rights to it and placed it
 3 # in the public domain under the Creative Commons CC0 1.0 waiver
 4 # (http://creativecommons.org/publicdomain/zero/1.0/).
 5 # 
 6 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 7 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 8 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 9 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
10 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
11 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
12 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 # 
14 # Retrieved from: http://en.literateprograms.org/Rot13_(Python)?oldid=16530
15 
16 
17 def rot13_char(ch):
18   if not ch.isalpha():
19     return ch
20 
21   ch_low = ch.lower()
22   if ch_low <= 'm':
23     dist = 13
24   else:
25     dist = -13
26   return chr(ord(ch) + dist)
27 
28 def rot13(s):
29   return ''.join( rot13_char(ch) for ch in s )
30 
31 if __name__ == '__main__':
32   try:
33     while True:
34       print rot13(raw_input())
35   except KeyboardInterrupt:
36       print 'Bye!'
37     


hijacker
hijacker
hijacker
hijacker