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
Prev Previous commit
Next Next commit
Add input validation and change function name to apply_rot13
  • Loading branch information
Y-Srivaishnavi authored Oct 29, 2024
commit 5efef35d8d481b40f450f65418e59741a479d22b
17 changes: 11 additions & 6 deletions ciphers/rot13.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
def dencrypt(s: str) -> str:
def apply_rot13(s: str) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
Performs a special case of the Caesar cipher.
Rotates the plaintext by 13 letters.
Also see: https://en.wikipedia.org/wiki/ROT13

Example usage:
>>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
>>> s = dencrypt(msg)
>>> s = apply_rot13(msg)
>>> s
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
>>> dencrypt(s) == msg
>>> apply_rot13(s) == msg
True
"""
if not isinstance(s, str):
return "The input must be a string. Please try again."
N = 13
out = ""
for c in s:
Expand All @@ -24,10 +29,10 @@ def dencrypt(s: str) -> str:
def main() -> None:
s0 = input("Enter message: ")

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

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


Expand Down