#message to be encrpyted/decrypted inputText = 'secret message' # encryption/decryption key key = 5 # encrpyt or decrypt mode = 'encrypt' # ledger ledger = 'abcdefghijklmnopqrstuvwxyz 1234567890' # output message outputText = '' for char in inputText: #find the index of the character in ledger inputIndex = ledger.find(char) # perform ecryption/decryption if mode == 'encrypt': outputIndex = inputIndex + key elif mode 'decrypt': outputIndex = inputIndex - key # handle wraparaound if outputIndex >= len(ledger): outputIndex = outputIndex - len(ledger) elif outputIndex < 0: outputIndex = outputIndex + len(ledger) # output outputText = outputText + ledger [outputIndex] print(outputText)