Compare commits

...

7 Commits

Author SHA1 Message Date
Srivaishnavi Yaddanapudi
934893fe0e
Merge 3a98cdab6e into f3f32ae3ca 2024-11-20 15:10:22 +05:30
pre-commit-ci[bot]
f3f32ae3ca
[pre-commit.ci] pre-commit autoupdate (#12385)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-18 22:07:12 +01:00
Srivaishnavi Yaddanapudi
3a98cdab6e
Change N into lowercase 2024-10-29 17:34:37 +05:30
Srivaishnavi Yaddanapudi
92d58b7109
Add `.split 2024-10-29 17:21:43 +05:30
Srivaishnavi Yaddanapudi
2bef9b9cb3
Update documentation 2024-10-29 17:06:56 +05:30
Srivaishnavi Yaddanapudi
5efef35d8d
Add input validation and change function name to apply_rot13 2024-10-29 17:04:58 +05:30
Srivaishnavi Yaddanapudi
4879a46be1
Fix number of rotations N as 13 (Resolves TheAlgorithms#12306) 2024-10-29 16:52:40 +05:30
2 changed files with 15 additions and 9 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.7.4
hooks:
- id: ruff
- id: ruff-format

View File

@ -1,14 +1,20 @@
def dencrypt(s: str, n: int = 13) -> str:
def apply_rot13(s: str) -> str:
"""
https://en.wikipedia.org/wiki/ROT13
Performs a special reversible case of the Caesar cipher.
Rotates a text 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:
if "A" <= c <= "Z":
@ -21,13 +27,13 @@ def dencrypt(s: str, n: int = 13) -> str:
def main() -> None:
s0 = input("Enter message: ")
s0 = input("Enter message: ").strip()
s1 = dencrypt(s0, 13)
s1 = apply_rot13(s0)
print("Encryption:", s1)
s2 = dencrypt(s1, 13)
print("Decryption: ", s2)
s2 = apply_rot13(s1)
print("Decryption:", s2)
if __name__ == "__main__":