2020-10-16 06:11:52 +00:00
|
|
|
def dencrypt(s: str, n: int = 13) -> str:
|
2020-03-08 06:04:21 +00:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
2019-10-05 05:14:13 +00:00
|
|
|
out = ""
|
2017-10-29 17:44:54 +00:00
|
|
|
for c in s:
|
2020-03-08 06:04:21 +00:00
|
|
|
if "A" <= c <= "Z":
|
2019-10-05 05:14:13 +00:00
|
|
|
out += chr(ord("A") + (ord(c) - ord("A") + n) % 26)
|
2020-03-08 06:04:21 +00:00
|
|
|
elif "a" <= c <= "z":
|
2019-10-05 05:14:13 +00:00
|
|
|
out += chr(ord("a") + (ord(c) - ord("a") + n) % 26)
|
2017-10-29 17:44:54 +00:00
|
|
|
else:
|
|
|
|
out += c
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
2021-04-04 05:22:12 +00:00
|
|
|
def main() -> None:
|
2020-03-08 06:04:21 +00:00
|
|
|
s0 = input("Enter message: ")
|
2017-10-29 17:44:54 +00:00
|
|
|
|
|
|
|
s1 = dencrypt(s0, 13)
|
2020-03-13 08:23:38 +00:00
|
|
|
print("Encryption:", s1)
|
2017-10-29 17:44:54 +00:00
|
|
|
|
|
|
|
s2 = dencrypt(s1, 13)
|
2020-03-13 08:23:38 +00:00
|
|
|
print("Decryption: ", s2)
|
2017-10-29 17:44:54 +00:00
|
|
|
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2020-03-08 06:04:21 +00:00
|
|
|
import doctest
|
2020-03-13 08:23:38 +00:00
|
|
|
|
2020-03-08 06:04:21 +00:00
|
|
|
doctest.testmod()
|
2017-10-29 17:44:54 +00:00
|
|
|
main()
|