Skip to content

Commit b47b1e7

Browse files
authored
Add a rot13 cipher in response to Issue RisingLight#7
1 parent 93067ce commit b47b1e7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Ciphers/rot13.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#rot13
2+
OFFSET_LOWER = ord('a')
3+
OFFSET_UPPER = ord('A')
4+
5+
def rot13(text):
6+
rot13_text = ''
7+
for i in range(len(text)):
8+
ch = text[i]
9+
if ch.isalpha():
10+
if(ch.islower()):
11+
offset = OFFSET_LOWER
12+
else:
13+
offset = OFFSET_UPPER
14+
rot13_text += chr(((ord(ch)-offset+13)%26+offset))
15+
else:
16+
rot13_text += ch
17+
return rot13_text
18+
19+
plain_text = input("Enter the string: ")
20+
print(rot13(plain_text))
21+
print(rot13(rot13(plain_text)))

0 commit comments

Comments
 (0)