From ec4d2897a9b05c8ef58611b4c5f4a31fca6991bf Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 30 May 2019 19:06:42 +0200 Subject: [PATCH 1/2] Atbash.py: Both raw_input() and unichr() were removed in Python 3 @sateslayer and @AnupKumarPanwar your reviews please. --- ciphers/Atbash.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ciphers/Atbash.py b/ciphers/Atbash.py index 4920e3049756..f04deb1e4efb 100644 --- a/ciphers/Atbash.py +++ b/ciphers/Atbash.py @@ -1,14 +1,21 @@ +try: # Python 2 + raw_input + unichr +except NameError: # Python 3 + raw_input = input + unichr = chr + + def Atbash(): - inp=raw_input("Enter the sentence to be encrypted ") output="" - for i in inp: - extract=ord(i) - if extract>=65 and extract<=90: - output+=(unichr(155-extract)) - elif extract>=97 and extract<=122: - output+=(unichr(219-extract)) + for i in raw_input("Enter the sentence to be encrypted "): + extract = ord(i) + if 65 <= extract <= 90: + output += unichr(155-extract) + elif 97 <= extract <= 122: + output += unichr(219-extract) else: output+=i - print (output) + print(output) -Atbash() ; +Atbash() From 297187f4959adedae548d02681b95de6f8ca7928 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 30 May 2019 19:16:22 +0200 Subject: [PATCH 2/2] Remove any leading / trailing whitespace from user input --- ciphers/Atbash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/Atbash.py b/ciphers/Atbash.py index f04deb1e4efb..162614c727ee 100644 --- a/ciphers/Atbash.py +++ b/ciphers/Atbash.py @@ -8,7 +8,7 @@ def Atbash(): output="" - for i in raw_input("Enter the sentence to be encrypted "): + for i in raw_input("Enter the sentence to be encrypted ").strip(): extract = ord(i) if 65 <= extract <= 90: output += unichr(155-extract)