266 lines
7.2 KiB
Python
266 lines
7.2 KiB
Python
|
#!/bin/python3
|
||
|
|
||
|
import hashlib, os
|
||
|
import tkinter as tk
|
||
|
from tkinter import messagebox
|
||
|
|
||
|
# from tkinter import ttk
|
||
|
|
||
|
## funktionen
|
||
|
def a_str(inp, leng):
|
||
|
if len(inp) < leng:
|
||
|
while len(inp) < leng:
|
||
|
inp += inp
|
||
|
inp = inp[:leng]
|
||
|
elif len(inp) > leng:
|
||
|
inp = inp[:leng]
|
||
|
return inp
|
||
|
|
||
|
|
||
|
def sha512(passwort):
|
||
|
sha512 = hashlib.sha512()
|
||
|
sha512.update(passwort.encode())
|
||
|
return sha512.hexdigest()
|
||
|
|
||
|
|
||
|
def crypt(text, key_hash):
|
||
|
key_hash = a_str(key_hash, len(text))
|
||
|
crypted_text = ""
|
||
|
for i in range(len(text)):
|
||
|
crypted_text += chr(ord(text[i]) ^ ord(key_hash[i]))
|
||
|
return crypted_text
|
||
|
|
||
|
|
||
|
def o(note, mode):
|
||
|
return open(f"{n_path}{note}.txt", mode, encoding="utf-8")
|
||
|
|
||
|
|
||
|
def nlist():
|
||
|
string = ""
|
||
|
notizen = []
|
||
|
if os.listdir(n_path) == []:
|
||
|
string += "Noch keine Notizen\n"
|
||
|
else:
|
||
|
string += "Deine Notizen:\n"
|
||
|
for a in os.listdir(n_path):
|
||
|
notizen.append(f"{a}"[:-4])
|
||
|
for n in notizen:
|
||
|
string += f" - {n}:\n"
|
||
|
datei = o(n, "r")
|
||
|
string += crypt(datei.read(), passwort) + "\n"
|
||
|
datei.close()
|
||
|
return [string, notizen]
|
||
|
|
||
|
|
||
|
def neditadd(notiz=str, text=str):
|
||
|
if not notiz + ".txt" in os.listdir(n_path):
|
||
|
if notiz + ".txt" in os.listdir(n_path):
|
||
|
back = "Notiz gibt es schon."
|
||
|
return back
|
||
|
back = "neue Notiz angelegt."
|
||
|
else:
|
||
|
back = "Erfolgreich gespeichert"
|
||
|
datei = o(notiz, "w")
|
||
|
datei.write(crypt(text, passwort))
|
||
|
datei.close()
|
||
|
return back
|
||
|
|
||
|
|
||
|
class eigene_fenster:
|
||
|
def welcome_w():
|
||
|
w_welcome = tk.Tk()
|
||
|
w_welcome.title("Welcome zu n")
|
||
|
w_welcome.geometry("450x300")
|
||
|
|
||
|
def ok():
|
||
|
global passwort
|
||
|
passwort = l_wpassword.get()
|
||
|
passwort = sha512(passwort)
|
||
|
w_welcome.destroy()
|
||
|
|
||
|
l_wtext = tk.Label(
|
||
|
w_welcome,
|
||
|
text="""
|
||
|
ACHTUNG: Falls du dein Passwort falsch eingibst überprüfe
|
||
|
erst ob deine Notizen richtig angezeigt werden sonnst falls
|
||
|
du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
||
|
|
||
|
ACHTUNG: Es kann seine das einige Zeichen wie Umlaute falsch
|
||
|
angezeigt werden können.
|
||
|
|
||
|
Passwort:""",
|
||
|
)
|
||
|
l_wpassword = tk.Entry(w_welcome)
|
||
|
l_wbutton = tk.Button(w_welcome, text="Start", command=ok)
|
||
|
l_wtext.pack()
|
||
|
l_wpassword.pack()
|
||
|
l_wbutton.pack(fill="x")
|
||
|
w_welcome.mainloop()
|
||
|
return passwort
|
||
|
|
||
|
def main():
|
||
|
class actions:
|
||
|
def edit():
|
||
|
notiz = eigene_dialoge.notiz_auswahl()
|
||
|
print("Notiz ausgewählt")
|
||
|
write_note = eigene_dialoge.notiz_dialog(notiz)
|
||
|
info = neditadd(write_note[0], write_note[1])
|
||
|
messagebox("Notiz", info)
|
||
|
|
||
|
def new():
|
||
|
pass
|
||
|
|
||
|
w_main = tk.Tk()
|
||
|
w_main.title("n")
|
||
|
w_main.geometry("800x600")
|
||
|
|
||
|
menu = tk.Menu(w_main)
|
||
|
w_main.config(menu=menu)
|
||
|
|
||
|
nmenu = tk.Menu(menu, tearoff=0)
|
||
|
menu.add_cascade(label="n", menu=nmenu)
|
||
|
nmenu.add_command(label="New", command=eigene_dialoge.notiz_dialog)
|
||
|
nmenu.add_command(label="refresh", command=tkf.refresh_list)
|
||
|
nmenu.add_command(label="edit", command=actions.edit)
|
||
|
# nmenu.add_command(label="delete", command=tkf.nlist)
|
||
|
|
||
|
moremenu = tk.Menu(menu, tearoff=0)
|
||
|
menu.add_cascade(label="more", menu=moremenu)
|
||
|
moremenu.add_command(label="secure", command=tkf.secure)
|
||
|
moremenu.add_command(label="help", command=tkf.help)
|
||
|
moremenu.add_command(label="debug", command=tkf.debug)
|
||
|
global notiz_list
|
||
|
notiz_list = tk.StringVar()
|
||
|
notiz_list.set(nlist()[0])
|
||
|
l_nlist = tk.Label(w_main, textvariable=notiz_list)
|
||
|
l_nlist.pack()
|
||
|
w_main.mainloop()
|
||
|
|
||
|
|
||
|
class eigene_dialoge:
|
||
|
def notiz_dialog(title):
|
||
|
notiz = o(title, "r")
|
||
|
notiz_dialog = tk.Tk()
|
||
|
|
||
|
def cancel():
|
||
|
global ret
|
||
|
|
||
|
ret = tk.StringVar(notiz_dialog)
|
||
|
ret.set([title, notiz.read()])
|
||
|
notiz_dialog.destroy()
|
||
|
print(ret.get())
|
||
|
|
||
|
def ok():
|
||
|
global ret
|
||
|
|
||
|
ret = tk.StringVar(notiz_dialog)
|
||
|
ret.set([ltitle.get(), linhalt.get()])
|
||
|
notiz_dialog.destroy()
|
||
|
print(ret.get())
|
||
|
|
||
|
lttitle = tk.Label(notiz_dialog, text="Titel:")
|
||
|
ltitle = tk.Entry(notiz_dialog)
|
||
|
ltitle.insert(0, title)
|
||
|
print(title)
|
||
|
ltinhalt = tk.Label(notiz_dialog, text="Inhalt:")
|
||
|
linhalt = tk.Entry(notiz_dialog)
|
||
|
print(notiz.read())
|
||
|
linhalt.insert(0, notiz.read())
|
||
|
lbutton_save = tk.Button(notiz_dialog, text="Save", command=ok)
|
||
|
lbutton_cancel = tk.Button(notiz_dialog, text="Abbrechen", command=cancel)
|
||
|
|
||
|
lttitle.pack()
|
||
|
ltitle.pack()
|
||
|
ltinhalt.pack()
|
||
|
linhalt.pack()
|
||
|
lbutton_save.pack()
|
||
|
lbutton_cancel.pack()
|
||
|
|
||
|
lbutton_save.pack(fill="x")
|
||
|
lbutton_cancel.pack(fill="x")
|
||
|
notiz_dialog.mainloop()
|
||
|
return ret.get()
|
||
|
|
||
|
def notiz_auswahl():
|
||
|
def done():
|
||
|
global ret
|
||
|
ret = gewählt.get()
|
||
|
auswahl.destroy()
|
||
|
|
||
|
auswahl = tk.Tk()
|
||
|
gewählt = tk.StringVar(auswahl)
|
||
|
gewählt.set("Notiz auswählen")
|
||
|
tauswahl = tk.Label(auswahl, text="Notiz:")
|
||
|
tauswahl.pack()
|
||
|
dropdown = tk.OptionMenu(auswahl, gewählt, *nlist()[1])
|
||
|
dropdown.pack()
|
||
|
button = tk.Button(auswahl, text="Auswählen", command=done)
|
||
|
button.pack(fill="x")
|
||
|
auswahl.mainloop()
|
||
|
return ret
|
||
|
|
||
|
|
||
|
class tkf:
|
||
|
def refresh_list():
|
||
|
notiz_list.set(nlist()[0])
|
||
|
|
||
|
def help():
|
||
|
messagebox.showinfo(
|
||
|
"help",
|
||
|
"""Hilfe:
|
||
|
edit = Bearbeite eine Notiz.
|
||
|
read = Zeige eine Notiz an.
|
||
|
add = Erstelle eine Notiz.
|
||
|
delete = Notiz löschen.
|
||
|
list = Zeigt dir deine Notizen nochmals an.
|
||
|
secure = Wie funktioniert die verschlüsselung.
|
||
|
debug = Zeigt Debug Infos.
|
||
|
exit = Beenden.
|
||
|
|
||
|
Bei Fehlern Bitte an Megamichi melden.""",
|
||
|
)
|
||
|
|
||
|
def secure():
|
||
|
messagebox.showinfo(
|
||
|
"sicherheit",
|
||
|
"""Zur Sicherheit:
|
||
|
Es wir ein SHA-512 Hash aus dein Passwort erstellt.
|
||
|
Und mit deinen Notizen und den auf die richtige Länge
|
||
|
angepassten Hash wir ein One-Time-Pad angewendet.
|
||
|
|
||
|
ACHTUNG: Falls du dein Passwort falsch eingibst überprüfe
|
||
|
erst ob deine Notizen richtig angezeigt werden sonst falls
|
||
|
du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
||
|
|
||
|
ACHTUNG: Es kann seine Das einige Zeichen wie Umlaute falsch
|
||
|
angezeigt werden können.""",
|
||
|
)
|
||
|
|
||
|
def debug():
|
||
|
messagebox.showinfo(
|
||
|
"Debug",
|
||
|
f"""Debug Informationen:
|
||
|
n_path={n_path}
|
||
|
pas_hash={passwort}""",
|
||
|
)
|
||
|
|
||
|
|
||
|
## variablen
|
||
|
passwort = "HALIHALLO"
|
||
|
##notizen pfad
|
||
|
n_path = os.path.dirname(os.path.abspath(__file__))
|
||
|
tzeichen = os.sep
|
||
|
n_path += tzeichen
|
||
|
if not os.path.exists(f"{n_path}n{tzeichen}"):
|
||
|
os.makedirs(f"{n_path}n{tzeichen}")
|
||
|
messagebox.showinfo("Verzeichniss", "Notizenverzeichniss angelegt.")
|
||
|
n_path += "n" + tzeichen
|
||
|
|
||
|
eigene_dialoge.notiz_dialog("dodel")
|
||
|
# eigene_dialoge.notiz_auswahl()
|
||
|
exit()
|
||
|
# Welcome screen
|
||
|
passwort = eigene_fenster.welcome_w()
|
||
|
# main fenster
|
||
|
eigene_fenster.main()
|