Skip to content

Resolves issue #12306 #12319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix number of rotations N as 13 (Resolves #12306)
  • Loading branch information
Y-Srivaishnavi authored Oct 29, 2024
commit 4879a46be1c056cceb46be12155796a75f070c68
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