From 0f229e0870050478a6b3fa1ecf60d73b694b98da Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 5 Jun 2019 03:09:04 +0200 Subject: [PATCH] Atbash.py: Both raw_input() and unichr() were removed in Python 3 (#855) * Atbash.py: Both raw_input() and unichr() were removed in Python 3 @sateslayer and @AnupKumarPanwar your reviews please. * Remove any leading / trailing whitespace from user input --- ciphers/Atbash.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ciphers/Atbash.py b/ciphers/Atbash.py index 4920e3049..162614c72 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 ").strip(): + 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()