May-29-2020, 06:52 AM
(This post was last modified: May-29-2020, 06:52 AM by lazerwolf101.)
(May-29-2020, 03:05 AM)DT2000 Wrote: You seem to be trying to decrypt a Caesar cypher. I have posted on this here.
It would help if you showed the whole code so we can see if the message is being encrypted correctly as well.
The encryption code isn't needed I made my own and works fine. I just need help with the very last lines of code in the decryption. Where the user is asked to input which key they want. and once the user has inputted what they want, that key will then be printed.
Here is my encryption code btw:
def encrypt(): global encrypted_message e_message = input("[E]Enter your message: ") e_key = input("[E]Enter your shift: ") e_key = int(e_key) print(e_message) print(e_key) seperate_message = [a for a in e_message] print(seperate_message) ascii_message = [ord(a) for a in e_message] print(ascii_message) shifted_message = [ord(a)+e_key for a in e_message] print(shifted_message) encrypted_message = " " for a in e_message: if a in alphabet: encrypted_message += alphabet[(alphabet.index(a)+e_key)%(len(alphabet))] print("Your encrypted message is: " + encrypted_message) pass
Decryption code:
LETTERS = 'abcdefghijklmnopqrstuvwxyz' d_message = input("Enter your message: ") print(d_message) for key in range(len(LETTERS)): translated = '' for symbol in d_message: if symbol in LETTERS: num = LETTERS.find(symbol) num = num - key if num < 0: num = num + len(LETTERS) translated = translated + LETTERS[num] else: translated = translated + symbol print('Key #%s: %s' % (key, translated)) option = input("Select your decrypted text. ") print(option)