From 6b20bddd0d90a9b826240fb8c249b870fcd13439 Mon Sep 17 00:00:00 2001 From: tebarius Date: Sat, 2 Dec 2023 18:20:30 +0100 Subject: [PATCH] =?UTF-8?q?j=C3=A4gerzaun-encrypt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .idea/Mysteryhelfer_pyCharm.iml | 1 + .idea/misc.xml | 3 ++ Mysteryhelfer.pyw | 54 +++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ec9bb4a..243cf14 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /data/config.txt +/experimentierbereich/ diff --git a/.idea/Mysteryhelfer_pyCharm.iml b/.idea/Mysteryhelfer_pyCharm.iml index 74d515a..871ce55 100644 --- a/.idea/Mysteryhelfer_pyCharm.iml +++ b/.idea/Mysteryhelfer_pyCharm.iml @@ -2,6 +2,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index bdd03ce..22213f3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/Mysteryhelfer.pyw b/Mysteryhelfer.pyw index da8a619..d6c875e 100644 --- a/Mysteryhelfer.pyw +++ b/Mysteryhelfer.pyw @@ -4310,9 +4310,58 @@ wird dann Base64-kodiert ausgegeben. Ausgabe.insert(1.0, "ASCII -> Base64:\n", "bu") Ausgabe.insert(1.0, "Umwandlung Base64 -> ASCII war nicht möglich.\n", "re") - # ------------------------------------------------------------------------------------------ + +def rail_encrypt(plain_text: str, rails: int): + arr = [["" for _ in range(len(plain_text))] for _ in range(rails)] + r = 0 + z = 0 + plus = True + for b in plain_text: + arr[r][z] = b + z += 1 + if r+1 == rails and plus: + plus = False + r -= 1 + elif r-1 < 0 and not plus: + plus = True + r += 1 + elif plus: + r += 1 + else: + r -= 1 + out = "" + for i in range(rails): + for j in range(len(plain_text)): + out += arr[i][j] + return out +def jaegerzaun_encrypt(): + trennlinie() + eingabetext = Eingabe.get(1.0, END) + eingabetext = eingabetext.strip().replace("\n", " ") + pw = PW_Eingabe.get() + pw = pw.strip() + if eingabetext == "": + Ausgabe.insert(1.0, """HILFE: [encrypt Jägerzaun] + Jägerzaun (auch Railfence oder ZigZag-Chiffre genannt) + + """ + "\n\n") + elif pw == "" or not pw.isdigit(): + Ausgabe.insert(1.0, "Bitte eine Zahl im Schlüsselfeld eingeben!!\n", "re") + else: + try: + if int(pw) < 2: + raise ValueError("Zahl zu klein") + Ausgabe.insert(1.0, rail_encrypt(eingabetext.replace(" ", ""), int(pw)) + "\n") + Ausgabe.insert(1.0, "ohne Leerzeichen\n", "bu") + Ausgabe.insert(1.0, rail_encrypt(eingabetext, int(pw)) + "\n") + Ausgabe.insert(1.0, "inkl. Leerzeichen\n", "bu") + except ValueError: + Ausgabe.insert(1.0, "Schlüsselzahl fehlerhaft oder kleiner als 2.\n", "re") + + +# ------------------------------------------------------------------------------------------ def knoeppe_aendern2(): B44.config(text="Button88", command="", bg=bgcolor_default, cursor="") B45.config(text="Button89", command="", bg=bgcolor_default, cursor="") @@ -4359,7 +4408,8 @@ def knoeppe_aendern1(): B53.config(text="Wortsuche-EN", command=wortsuche_en, bg="#33aa00", cursor='question_arrow', font=schrift) B54.config(text="Reverse-Wherigo", command=reversewig, bg="#FFA94F", cursor='question_arrow', font=schrift) B55.config(text="Base64<->ASCII", command=base64_ascii, bg="#7777ff", cursor='question_arrow', font=schrift) - B56.config(text="Button78", command="", bg=bgcolor_default, cursor="") + B56.config(text="Jägerzaun kodieren", command=jaegerzaun_encrypt, bg="#3388aa", cursor='question_arrow', + font=schrift) B57.config(text="Button79", command="", bg=bgcolor_default, cursor="") B58.config(text="Button80", command="", bg=bgcolor_default, cursor="") B59.config(text="Button81", command="", bg=bgcolor_default, cursor="")