Nicht sicher, warum dies nicht funktioniert. Dies soll einen Satz verschlüsseln und entschlüsseln. Ich bekomme die richtigen Buchstaben zurück, aber sie sind nicht in der richtigen Reihenfolge .Probleme mit Python-Entschlüsselung und Verschlüsselungsalgorithmus
def get_encrypt(original_text,dictionary):
#4
match= ""
for base in original_text:
match += dictionary[base]
return match
def rev_look(encrypted_text, dictionary):
match_key = []
for key in dictionary:
i = 0
for base in encrypted_text:
print(base)
if dictionary[key] == base:
match_key.append(key)
i += 1
return match_key
def main():
print('* Simple Substitution Cipher Tool *')
#Define the dictionary
dictionary = {' ':' ','a':'p', 'b':'h', 'c':'q', 'd':'g', 'e':'i', 'f':'u', 'g':'m', 'h':'e', 'i':'a', 'j':'y', 'k':'l', 'l':'n','m':'o', 'n':'f', 'o':'d', 'p':'x', 'q':'j', 'r':'k', 's':'r', 't':'c', 'u':'v', 'v':'s', 'w':'t', 'x':'z', 'y':'w', 'z':'b'}
#2
original_text =(input('Please enter the original text: '))
#3
encrypted_text = get_encrypt(original_text,dictionary)
print('The encrypted text is: ', encrypted_text)
print('The decrypted text is: ', rev_look(encrypted_text,dictionary))
main()
Vielleicht iterieren die Zeichen im Text bekommen dann * finde * das Zeichen im Wörterbuch - nicht umgekehrt. - aber das scheint für mich in Ordnung zu sein. "foo" -> "udd" -> "foo" – wwii