From e2e4599c25130499ddf31f9eaf90f1814f76014f Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Fri, 6 Jan 2023 21:03:47 +0200 Subject: [PATCH] Update Lesson 2 Task %*f#ncA0#>? to work without libraries --- Lesson_2/We know/dumb_decryptor.py | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Lesson_2/We know/dumb_decryptor.py b/Lesson_2/We know/dumb_decryptor.py index 52ffcb5..016a1d5 100644 --- a/Lesson_2/We know/dumb_decryptor.py +++ b/Lesson_2/We know/dumb_decryptor.py @@ -5,7 +5,35 @@ # Return codes: # 0 - OK -rot13 = str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', - 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm') +def isUppercase(chr): + if chr >= "A" and chr <= "Z": + return True + else: + return False -print(input("Enter message: ").translate(rot13)) +def isLowercase(chr): + if chr >= "a" and chr <= "z": + return True + else: + return False + +def isLetter(chr): + if isUppercase(chr) or isLowercase(chr): + return True + else: + return False + +string = input("Enter message: ") +newstring = '' + +for i in range(len(string)): + if not isLetter(string[i]): + continue + uppercase = isUppercase(string[i]) + newOrd = ord(string[i]) + 13 + if isLetter(chr(newOrd)) and uppercase == isUppercase(chr(newOrd)): + newstring += chr(newOrd) + else: + newstring += chr(newOrd - 26) + +print(newstring)