-2

`

dic = {
     'A': 'o78t6df', 'B': '8f6pifg', 'C': 'd8s64ag', 'D': '09h8u0q', 'E': 'u6sr4a7', 'F': 'x4tz86u', 'G': '86xrd6y', 'H': 'uiztxr6', 'I': 're56tex', 'J': 'ot76t6x', 
     'K': '8t97tc8', 'L': 'do7ztrd', 'M': 'p8t5s65', 'N': 'p8d6zrx', 'O': 'kzrxyrt', 'P': 'p86e7ea', 'Q': 'lutsd53', 'R': 'o785sde', 'S': 'olzsr53', 'T': 'wrp8z76', 
     'U': 'olutxcd', 'V': 'ut5aesq', 'W': 'nyvxu64', 'X': 't4w3qfs', 'Y': 'z532syd', 'Z': 'kzfxyt4', ' ': ' ', '1': 'i6rsweq', '2': 'uteas12', '3': 'p7g9txx', 
     '4': 'iz765s9', '5': 'ddd5tx1', '6': 'k7w4x49', '7': 'w33rr6y', '8': 'y54xsqw', '9': 'ol75sdy', '0': 'bbi75sa', '!': 'utdf55y', '?': 'uiw123x', '"': 'setuuwa', 
     '(': 'uzt5eys', ')': 'lutzcq1', '=': '6q245ss', '§': '1bc1121', '%': 'xyfvz45', '&': 'erw3646', '#': 'zutes34', '-': '35qw4z4', ',': 'q2543we', '/': 'q352s4e'
}

if choice_start=='e':
    print(Fore.GREEN + '► ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Your Message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = input(Fore.RESET + '⌬  ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Secret message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = message.upper()
    characters_list = []
    characters_list[:0] = message
    for i in characters_list:
        print(Fore.GREEN + dic[i])
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    time.sleep(50)

elif choice_start=='d':
    print(Fore.GREEN + '► Decyrpt')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Encrypted Message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = input(Fore.RESET + '⌬  ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Decrypted message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')


dict = {'a': 'a1', 'b': 'b1'}
list = [a1]

...

print('key from a1 is: (key x)')

`

I want to decrypt the message, but dont know how. (I am a beginner!)

So that when se user types in o78t6df the code prints out A. But i need this for whole sentences.

Can someone help me?

Gimojy
  • 3
  • 6
  • I'm confused, are you trying to match the key or the value? – DeepSpace Dec 13 '22 at 09:07
  • 1
    Welcome to StackOverflow. "I tried some own code." Then show your work so far so readers know what you've tried already. – Abirbhav G. Dec 13 '22 at 09:07
  • 1
    Shouldn't it be `list = ['a1']` (and by the way, DON'T name your list `list` : you're overwriting a Python keyword, which can be bad! – Swifty Dec 13 '22 at 09:09
  • 1
    @Swifty correct suggestion but not a keyword, just a built-in type. If it was a keyword then it would not have been possible to overwrite – DeepSpace Dec 13 '22 at 09:10
  • @DeepSpace the value sould match with the word in the list – Gimojy Dec 13 '22 at 09:17
  • @Swifty yes i know, in my code the list is named characters_list, i just wrote it as an example – Gimojy Dec 13 '22 at 09:19
  • I imagine your `dic` is used for coding a message; perhaps you want to create a reversed dic for decoding ? In this case, this might help: https://stackoverflow.com/questions/483666/reverse-invert-a-dictionary-mapping – Swifty Dec 13 '22 at 14:45

1 Answers1

0

your description is confusing. but seems you are looking for something like this.

my_dict = {'a': 'a1', 'b': 'b1'}
my_list = ['a1']
for item in my_dict:
    if my_list[0] == my_dict[item]:
        print('key from a1 is: {}'.format(item))

if it's your goal so end. if not edit your question with more explanation.

edit: if your list contains more, use another for for that!

Saeed Ramezani
  • 462
  • 6
  • 20
  • 1
    ... which beats the entire purpose of using a dict. If OP needs this they might as well build the dict the other way around – DeepSpace Dec 13 '22 at 09:23