Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#201 from t0rr3sp3dr0/master
Browse files Browse the repository at this point in the history
ROT13
  • Loading branch information
harshildarji authored Oct 31, 2017
2 parents 9dfd0a6 + 75af340 commit 991d09a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def dencrypt(s, n):
out = ''
for c in s:
if c >= 'A' and c <= 'Z':
out += chr(ord('A') + (ord(c) - ord('A') + n) % 26)
elif c >= 'a' and c <= 'z':
out += chr(ord('a') + (ord(c) - ord('a') + n) % 26)
else:
out += c
return out


def main():
s0 = 'HELLO'

s1 = dencrypt(s0, 13)
print(s1) # URYYB

s2 = dencrypt(s1, 13)
print(s2) # HELLO


if __name__ == '__main__':
main()

0 comments on commit 991d09a

Please sign in to comment.