From 2b6ec3a7d6f43e463dee452aed32bb5b7df4b52a Mon Sep 17 00:00:00 2001 From: Aakash Dinkar <35952953+aakashdinkar@users.noreply.github.com> Date: Fri, 6 Mar 2020 11:35:10 +0530 Subject: [PATCH 1/3] update rot13.py --- ciphers/rot13.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ciphers/rot13.py b/ciphers/rot13.py index a7b546511967..f352baed632e 100644 --- a/ciphers/rot13.py +++ b/ciphers/rot13.py @@ -11,13 +11,13 @@ def dencrypt(s, n): def main(): - s0 = "HELLO" + s0 = input("Enter message: ") s1 = dencrypt(s0, 13) - print(s1) # URYYB + print("Encryption: "+s1) s2 = dencrypt(s1, 13) - print(s2) # HELLO + print("Decryption: "+s2) if __name__ == "__main__": From cdf97a0608d18a97698d8a86b45c1d282c5774fe Mon Sep 17 00:00:00 2001 From: Aakash Dinkar <35952953+aakashdinkar@users.noreply.github.com> Date: Sun, 8 Mar 2020 08:52:28 +0530 Subject: [PATCH 2/3] Update rot13.py --- ciphers/rot13.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ciphers/rot13.py b/ciphers/rot13.py index f352baed632e..2212afdb4cbc 100644 --- a/ciphers/rot13.py +++ b/ciphers/rot13.py @@ -21,4 +21,6 @@ def main(): if __name__ == "__main__": + import doctest + doctest.testmod() main() From 7d724031602689942dadeb913bc27ec8342d6727 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 8 Mar 2020 06:58:18 +0100 Subject: [PATCH 3/3] Type hints, doctests, URL to Wikipedia --- ciphers/rot13.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ciphers/rot13.py b/ciphers/rot13.py index 2212afdb4cbc..7a5954f89dd3 100644 --- a/ciphers/rot13.py +++ b/ciphers/rot13.py @@ -1,9 +1,19 @@ -def dencrypt(s, n): +def dencrypt(s: str, n: int=13): + """ + 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 + """ out = "" for c in s: - if c >= "A" and c <= "Z": + if "A" <= c <= "Z": out += chr(ord("A") + (ord(c) - ord("A") + n) % 26) - elif c >= "a" and c <= "z": + elif "a" <= c <= "z": out += chr(ord("a") + (ord(c) - ord("a") + n) % 26) else: out += c @@ -14,10 +24,10 @@ def main(): s0 = input("Enter message: ") s1 = dencrypt(s0, 13) - print("Encryption: "+s1) + print("Encryption:", s1) s2 = dencrypt(s1, 13) - print("Decryption: "+s2) + print("Decryption: ", s2) if __name__ == "__main__":