{}
run-icon
main.py
user_text = input(" please enter your text : ") user_text = user_text.replace(" ","") # to remove spaces quest=int(input(" choose 1 if encryption and 2 if decryption : ")) coded_text =[] if quest == 1: ascii_of_user = [ord(c.lower()) for c in user_text] # where lower() to make lowe and upper treated the same , c is the ascii of characters of text i working on for c in ascii_of_user : if 'a' <= chr(c) <= 'z': #alphabets starts from a to z coded_text.append(chr((c - ord('a') + 2) % 26 + ord('a'))) # -ord('a') = 97 to identify the order of character in order of alphabet , +2 to shift , % 26 to return the character if it y or z (26 related to we have 26 letters) then + ord('a') to get the position back to the needed value else : coded_text.append(chr(c)) final_coded = "" .join(coded_text) # join is to make text in only one string not character by character in list else : ascii_of_user = [ord(c.lower()) for c in user_text] # where lower() to make lowe and upper treated the same , c is the ascii of characters of text i working on for c in ascii_of_user : if 'a' <= chr(c) <= 'z': #alphabets starts from a to z coded_text.append(chr((c - ord('a') - 2) % 26 + ord('a'))) # -ord('a') = 97 to identify the order of character in order of alphabet , +2 to shift , % 26 to return the character if it y or z (26 related to we have 26 letters) then + ord('a') to get the position back to the needed value else : coded_text.append(chr(c)) final_coded = "" .join(coded_text) # join is to make text in only one string not character by character in list print(final_coded)
Output