-2

As the title says, I have my program functioning with capitalization but I would like it to have compatibility with uncapitalized and capitalized inputs. It should return as capitalized encryption.

decrypted = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ.1234567890 "
encrypted = b"SE2RL.1W5A0Z8D7H4B9M6JX3FTNVQGPUOYCKI "

encrypt_table = bytes.maketrans(decrypted, encrypted)
decrypt_table = bytes.maketrans(encrypted, decrypted)

result = ''
choice = ''
message = ''

while choice != 'X':
    choice = input("\n Do you want to encrypt or decrypt the message?\n E to encrypt, D to decrypt or X to exit program. ")

    if choice == 'E':
        message = input('\nEnter message for encryption: ')
        result = message.translate(encrypt_table)
        print(result + '\n\n')

    elif choice == 'D':
        message = input('\nEnter message to decrypt: ')
        result = message.translate(decrypt_table)
        print(result + '\n\n')

    elif choice != 'X':
        print('You have entered an invalid input, please try again. \n\n')
petezurich
  • 9,280
  • 9
  • 43
  • 57
Ean Crosby
  • 19
  • 3

1 Answers1

0

You could either add all the lowercase letters to your decrypted string, or you could use .upper() on the user input.

Also, this is technically a substitution cipher. To make it an true "encryption" you need to have a key that "unlocks" the encrypted text. See the Caesar cipher for a very simple example (in fact it is a kind of substitution cipher itself :P), where the key is the number of shifts. Or see AES, which is arguably the best encryption algorithm out there so far.

Have a nice day
  • 1,007
  • 5
  • 11