Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting text as an input
#3
(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)
Reply


Messages In This Thread
Selecting text as an input - by lazerwolf101 - May-28-2020, 11:50 PM
RE: Selecting text as an input - by DT2000 - May-29-2020, 03:05 AM
RE: Selecting text as an input - by lazerwolf101 - May-29-2020, 06:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,165 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  Modify Input() text catosp 6 2,923 Jun-08-2020, 10:48 PM
Last Post: deanhystad
  Python QGIS tool that replaces layout text labels with attributes from an input table geodenn92 1 2,693 Aug-13-2019, 06:05 AM
Last Post: buran
  Four text files input combinations into an output file mhyga 2 2,228 Jul-28-2019, 06:52 PM
Last Post: ThomasL
  removing tabs from input text jenya56 3 3,246 Mar-28-2019, 03:10 PM
Last Post: DeaD_EyE
  How do I shorten my input options? - text adventure ShiningKnight 3 4,675 Jan-01-2017, 03:21 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020