mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
Compare commits
7 Commits
f577a1966d
...
934893fe0e
Author | SHA1 | Date | |
---|---|---|---|
|
934893fe0e | ||
|
f3f32ae3ca | ||
|
3a98cdab6e | ||
|
92d58b7109 | ||
|
2bef9b9cb3 | ||
|
5efef35d8d | ||
|
4879a46be1 |
|
@ -16,7 +16,7 @@ repos:
|
||||||
- id: auto-walrus
|
- id: auto-walrus
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.7.3
|
rev: v0.7.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
|
|
@ -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!!"
|
>>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!"
|
||||||
>>> s = dencrypt(msg)
|
>>> s = apply_rot13(msg)
|
||||||
>>> s
|
>>> s
|
||||||
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
|
"Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!"
|
||||||
>>> dencrypt(s) == msg
|
>>> apply_rot13(s) == msg
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
if not isinstance(s, str):
|
||||||
|
return "The input must be a string. Please try again."
|
||||||
|
n = 13
|
||||||
out = ""
|
out = ""
|
||||||
for c in s:
|
for c in s:
|
||||||
if "A" <= c <= "Z":
|
if "A" <= c <= "Z":
|
||||||
|
@ -21,13 +27,13 @@ def dencrypt(s: str, n: int = 13) -> str:
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
s0 = input("Enter message: ")
|
s0 = input("Enter message: ").strip()
|
||||||
|
|
||||||
s1 = dencrypt(s0, 13)
|
s1 = apply_rot13(s0)
|
||||||
print("Encryption:", s1)
|
print("Encryption:", s1)
|
||||||
|
|
||||||
s2 = dencrypt(s1, 13)
|
s2 = apply_rot13(s1)
|
||||||
print("Decryption: ", s2)
|
print("Decryption:", s2)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user