Fix number of rotations N as 13 (Resolves TheAlgorithms#12306)

This commit is contained in:
Srivaishnavi Yaddanapudi 2024-10-29 16:52:40 +05:30 committed by GitHub
parent 52602ea5b6
commit 4879a46be1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
def dencrypt(s: str, n: int = 13) -> str:
def dencrypt(s: str) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
@ -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