import sys special_letters = { "ã": "a", "á": "a", "à": "a", "é": "e", "ê": "e", "í": "i", "ó": "o", "õ": "o", "ô": "o", "ú": "u", "ç": "c" } special_chars = { " ": " ", ".": ".", ",": ",", ";": ";", ":": ":", "!": "!", "?": "?", "(": "(", ")": ")" } caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' def cesar(string, key): new_string = "" for letter in string: if letter in special_chars: new_string += special_chars[letter] continue if letter in special_letters: letter = special_letters[letter] if letter not in caracteres: continue index = caracteres.index(letter) new_index = (index + key) % len(caracteres) new_letter = caracteres[new_index] new_string += new_letter return new_string if __name__ == "__main__": if len(sys.argv) != 4: print("Usage: python3 cesar.py -c/-d [key] [string]") sys.exit(1) encrypt = True if sys.argv[1] == "-d": encrypt = False key = int(sys.argv[2]) string = sys.argv[3] if not encrypt: key *= -1 print(cesar(string, key)) # # [A-Z, a-z, 0-9] # if ord('0') <= ord(letter) <= ord('9'): # if new_letter > ord('9'): # new_letter += 7 # 9 + 1 = A # elif new_letter < ord('0'): # new_letter += 75 # 0 - 1 = z # elif letter.isupper(): # if new_letter > ord('Z'): # new_letter += 6 # Z + 1 = a # elif new_letter < ord('A'): # new_letter -= 7 # A - 1 = 9 # else: # if new_letter > ord('z'): # new_letter -= 75 # z + 1 = 0 # elif new_letter < ord('a'): # new_letter -= 6 # a - 1 = Z