私は2つのボタンとテキストフィールドでGUIを表示する小さなスクリプトをPythonで書いています。テキスト領域に入力して暗号化をクリックすると、突然テキストが狂ったように見えます。 coooooool。私のpython暗号化ソフトウェアが動作していません
ですが、復号化すると元に戻りません。コードはここにあります
from Tkinter import *
import ttk
root = Tk()
textArea = Text(root, state = "normal")
def encrypt():
message = textArea.get('1.0', 'end')
newMessage = ''
lastChar = ''
for c in message:
if lastChar != '':
newMessage += chr((ord(c) + ord(lastChar)) % 256)
lastChar = chr((ord(c) + ord(lastChar)) % 256)
else:
newMessage += chr((ord(c) + 5) % 256)
lastChar = chr((ord(c) + 5) % 256)
textArea.delete('1.0', 'end')
textArea.insert('end', newMessage)
def decrypt():
message = textArea.get('1.0', 'end')
newMessage = ''
lastChar = ''
for c in message:
if lastChar != '':
newMessage += chr((ord(c) - ord(lastChar)) % 256)
lastChar = chr((ord(c) - ord(lastChar)) % 256)
else:
newMessage += chr((ord(c) - 5) % 256)
lastChar = chr((ord(c) - 5) % 256)
textArea.delete('1.0', 'end')
textArea.insert('end', newMessage)
encrypt = ttk.Button(root, text = "Encrypt", command = encrypt)
encrypt.pack({"side": "top"})
decrypt = ttk.Button(root, text = "Decrypt", command = decrypt)
decrypt.pack({"side": "top"})
textArea.pack({"side": "bottom"});
mainloop()
問題はそれが元のテキストを表示しないことです。それはちょうどそれをより秘密にするようです。何がここに間違っていますか?助けてください。
更新: は5を追加するだけで変更されています。つまり、最後の文字にコード値を追加する部分です。それでも問題は1つあります。新しい行とこの奇妙な行の文字(パイプではなく---> |)を追加します。
コードは修正されました。ありがとう。ここでの結果は次のとおりです。 WW1ueCVueCV1d2p5eX4laHR0cTMlWW1mc3AlfnR6JXh5ZmhwJXR7andrcXR8JWt0dyV5bWolZnN4fGp3Mw8 =
それは5を奪うしないように、私は復号化を行った後、それが働きました。再度、感謝します。
だけでなく、長い新しいラインが復号化されますよう、それは何を問題ではありませんか?私はちょうどあなたがメッセージを書いてそれを暗号化し、おそらく友人にそれを送り、彼にそれを解読させる小さなことであることを望んでいました。助けてくれてありがとう –
@AidanMuellerそれは問題ありません。データをBase64でエンコーディングし、文字列型として格納しないでください。大丈夫です。 – Borealid
私はこれがばかな質問ではないことを願っています。どうすればいいのですか? –