-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrot13.py
More file actions
31 lines (26 loc) · 817 Bytes
/
Copy pathrot13.py
File metadata and controls
31 lines (26 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/enc python
"""
A simple function to compute rot13 encoding
ROT13 encryption
Applying ROT13 to a piece of text merely requires examining its alphabetic
characters and replacing each one by the letter 13 places further along in
the alphabet, wrapping back to the beginning if necessary
"""
import string
def rot13a(text):
# loop through the letters
new_text = ""
for c in text:
# do upper and lower case separately
if c in string.ascii_lowercase:
o = ord(c) + 13
if o > ord('z'):
o = ord('a')-1 + o-ord('z')
elif c in string.ascii_uppercase:
o = ord(c) + 13
if o > ord('Z'):
o = ord('A')-1 + o-ord('Z')
else:
o = ord(c)
new_text += chr(o)
return new_text