Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed5d112

Browse files
Merge pull request #13 from godfreyduke/patch-1
Add a rot13 cipher in response to Issue #7
2 parents 6f0077b + b47b1e7 commit ed5d112

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎Ciphers/rot13.py‎

Lines changed: 21 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /