Skip to content

Commit

Permalink
Fix number of rotations N as 13 (Resolves TheAlgorithms#12306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Srivaishnavi authored Oct 29, 2024
1 parent 52602ea commit 4879a46
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def dencrypt(s: str, n: int = 13) -> str:
def dencrypt(s: str) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
Expand All @@ -9,12 +9,13 @@ def dencrypt(s: str, n: int = 13) -> str:
>>> dencrypt(s) == msg
True
"""
N = 13
out = ""
for c in s:
if "A" <= c <= "Z":
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
out += chr(ord("A") + (ord(c) - ord("A") + N) % 26)
elif "a" <= c <= "z":
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
out += chr(ord("a") + (ord(c) - ord("a") + N) % 26)
else:
out += c
return out
Expand Down

0 comments on commit 4879a46

Please sign in to comment.