MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / dencrypt

Function dencrypt

ciphers/rot13.py:1–20  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1def 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
23def main() -> None:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected