https://en.wikipedia.org/wiki/ROT13 >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!" >>> s = dencrypt(msg) >>> s "Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!" >>> dencrypt(s) == msg True
(s: str, n: int = 13)
| 1 | def dencrypt(s: str, n: int = 13) -> str: |
| 2 | """ |
| 3 | https://en.wikipedia.org/wiki/ROT13 |
| 4 | |
| 5 | >>> msg = "My secret bank account number is 173-52946 so don't tell anyone!!" |
| 6 | >>> s = dencrypt(msg) |
| 7 | >>> s |
| 8 | "Zl frperg onax nppbhag ahzore vf 173-52946 fb qba'g gryy nalbar!!" |
| 9 | >>> dencrypt(s) == msg |
| 10 | True |
| 11 | """ |
| 12 | out = "" |
| 13 | for c in s: |
| 14 | if "A" <= c <= "Z": |
| 15 | out += chr(ord("A") + (ord(c) - ord("A") + n) % 26) |
| 16 | elif "a" <= c <= "z": |
| 17 | out += chr(ord("a") + (ord(c) - ord("a") + n) % 26) |
| 18 | else: |
| 19 | out += c |
| 20 | return out |
| 21 | |
| 22 | |
| 23 | def main() -> None: |