Skip to content

Commit

Permalink
Merge pull request #13 from godfreyduke/patch-1
Browse files Browse the repository at this point in the history
Add a rot13 cipher in response to Issue #7
  • Loading branch information
imabhishekkumar authored Oct 24, 2019
2 parents 6f0077b + b47b1e7 commit ed5d112
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#rot13
OFFSET_LOWER = ord('a')
OFFSET_UPPER = ord('A')

def rot13(text):
rot13_text = ''
for i in range(len(text)):
ch = text[i]
if ch.isalpha():
if(ch.islower()):
offset = OFFSET_LOWER
else:
offset = OFFSET_UPPER
rot13_text += chr(((ord(ch)-offset+13)%26+offset))
else:
rot13_text += ch
return rot13_text

plain_text = input("Enter the string: ")
print(rot13(plain_text))
print(rot13(rot13(plain_text)))

0 comments on commit ed5d112

Please sign in to comment.