Skip to content
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

Fix 12306 used list instead of string in rot13.py and removed n #12363

Closed
Changes from all commits
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
11 changes: 6 additions & 5 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,24 +9,25 @@ def dencrypt(s: str, n: int = 13) -> str:
>>> dencrypt(s) == msg
True
"""
out = ""
out: list[str] = []
n = 13
for c in s:
if "A" <= c <= "Z":
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
elif "a" <= c <= "z":
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
else:
out += c
return out
return "".join(out)


def main() -> None:
s0 = input("Enter message: ")

s1 = dencrypt(s0, 13)
s1 = dencrypt(s0)
print("Encryption:", s1)

s2 = dencrypt(s1, 13)
s2 = dencrypt(s1)
print("Decryption: ", s2)


Expand Down
Loading