2023-10-21 22:10:11 +02:00
|
|
|
import hashlib,os
|
|
|
|
import tkinter as tk
|
2023-11-19 21:07:48 +01:00
|
|
|
from tkinter import messagebox
|
2023-10-21 22:10:11 +02:00
|
|
|
#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():
|
2023-11-19 21:07:48 +01:00
|
|
|
string = ""
|
|
|
|
notizen = []
|
2023-10-21 22:10:11 +02:00
|
|
|
if os.listdir(n_path) == []:
|
2023-11-19 21:07:48 +01:00
|
|
|
string += "Noch keine Notizen\n"
|
2023-10-21 22:10:11 +02:00
|
|
|
else:
|
2023-11-19 21:07:48 +01:00
|
|
|
string += "Deine Notizen:\n"
|
2023-10-21 22:10:11 +02:00
|
|
|
for a in os.listdir(n_path):
|
2023-11-19 21:07:48 +01:00
|
|
|
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):
|
2023-11-20 21:44:11 +01:00
|
|
|
if notiz+".txt" in os.listdir(n_path):
|
2023-11-19 21:07:48 +01:00
|
|
|
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
|
2023-11-20 21:44:11 +01:00
|
|
|
|
2023-11-20 20:20:46 +01:00
|
|
|
class eigene_fenster:
|
|
|
|
def welcome_w():
|
|
|
|
w_welcome = tk.Tk()
|
|
|
|
w_welcome.title("Welcome zu n")
|
|
|
|
w_welcome.geometry("450x300")
|
2023-11-20 21:44:11 +01:00
|
|
|
def ok():
|
|
|
|
global passwort
|
|
|
|
passwort = l_wpassword.get()
|
|
|
|
passwort = sha512(passwort)
|
|
|
|
w_welcome.destroy()
|
2023-11-20 20:20:46 +01:00
|
|
|
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.
|
2023-10-21 22:10:11 +02:00
|
|
|
|
2023-11-20 20:20:46 +01:00
|
|
|
ACHTUNG: Es kann seine das einige Zeichen wie Umlaute falsch
|
|
|
|
angezeigt werden können.
|
|
|
|
|
|
|
|
Passwort:""")
|
|
|
|
l_wpassword = tk.Entry(w_welcome)
|
2023-11-20 21:44:11 +01:00
|
|
|
l_wbutton = tk.Button(w_welcome, text="Start" ,command=ok)
|
2023-11-20 20:20:46 +01:00
|
|
|
l_wtext.pack()
|
|
|
|
l_wpassword.pack()
|
|
|
|
l_wbutton.pack(fill="x")
|
|
|
|
w_welcome.mainloop()
|
|
|
|
return passwort
|
|
|
|
|
|
|
|
def main():
|
2023-11-20 21:44:11 +01:00
|
|
|
class actions():
|
|
|
|
def edit():
|
|
|
|
notiz = eigene_dialoge.notiz_auswahl()
|
|
|
|
write_note = eigene_dialoge.notiz_dialog(notiz)
|
|
|
|
info = neditadd(write_note[0],write_note[1])
|
|
|
|
messagebox("Notiz",info)
|
|
|
|
def new():
|
|
|
|
pass
|
2023-11-20 20:20:46 +01:00
|
|
|
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)
|
2023-11-20 21:44:11 +01:00
|
|
|
nmenu.add_command(label="New", command=eigene_dialoge.notiz_dialog)
|
2023-11-20 20:20:46 +01:00
|
|
|
nmenu.add_command(label="refresh", command=tkf.refresh_list)
|
2023-11-20 21:44:11 +01:00
|
|
|
nmenu.add_command(label="edit", command=actions.edit)
|
2023-11-20 20:20:46 +01:00
|
|
|
#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()
|
2023-11-19 21:07:48 +01:00
|
|
|
notiz_list.set(nlist()[0])
|
2023-11-20 20:20:46 +01:00
|
|
|
l_nlist = tk.Label(w_main, textvariable=notiz_list)
|
|
|
|
l_nlist.pack()
|
|
|
|
w_main.mainloop()
|
2023-11-19 21:07:48 +01:00
|
|
|
|
2023-11-20 20:20:46 +01:00
|
|
|
|
|
|
|
class eigene_dialoge:
|
|
|
|
def notiz_dialog(title):
|
2023-11-20 21:44:11 +01:00
|
|
|
notiz = o(title,"r")
|
2023-11-19 21:07:48 +01:00
|
|
|
w_editnotiz = tk.Tk()
|
2023-11-20 20:20:46 +01:00
|
|
|
def cancel():
|
2023-11-20 21:44:11 +01:00
|
|
|
w_editnotiz.destroy()
|
2023-11-20 20:20:46 +01:00
|
|
|
def ok():
|
2023-11-20 21:44:11 +01:00
|
|
|
global ret
|
|
|
|
ret = [l_wtitle.get(),l_winhalt.get()]
|
|
|
|
w_editnotiz.destroy()
|
2023-11-19 21:07:48 +01:00
|
|
|
|
|
|
|
l_wttitle = tk.Label(w_editnotiz, text="Titel:")
|
|
|
|
l_wtitle = tk.Entry(w_editnotiz)
|
|
|
|
l_wtitle.insert(0,title)
|
|
|
|
l_wtinhalt = tk.Label(w_editnotiz, text="Inhalt:")
|
|
|
|
l_winhalt = tk.Entry(w_editnotiz)
|
|
|
|
l_winhalt.insert(0,notiz.read())
|
2023-11-20 20:20:46 +01:00
|
|
|
l_button_save = tk.Button(w_editnotiz, text="Save" ,command=ok)
|
|
|
|
l_button_cancel = tk.Button(w_editnotiz, text="Abbrechen" ,command=cancel)
|
2023-11-19 21:07:48 +01:00
|
|
|
|
|
|
|
l_wttitle.pack()
|
|
|
|
l_wtitle.pack()
|
|
|
|
l_wtinhalt.pack()
|
|
|
|
l_winhalt.pack()
|
|
|
|
l_button_save.pack()
|
|
|
|
l_button_cancel.pack()
|
|
|
|
|
|
|
|
l_button_save.pack(fill="x")
|
|
|
|
l_button_cancel.pack(fill="x")
|
|
|
|
w_editnotiz.mainloop()
|
2023-11-20 21:44:11 +01:00
|
|
|
return ret
|
|
|
|
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
|
2023-11-20 20:20:46 +01:00
|
|
|
|
2023-11-20 21:44:11 +01:00
|
|
|
class tkf :
|
2023-11-20 20:20:46 +01:00
|
|
|
def refresh_list():
|
|
|
|
notiz_list.set(nlist()[0])
|
2023-11-20 21:44:11 +01:00
|
|
|
|
2023-10-21 22:10:11 +02:00
|
|
|
|
|
|
|
def help():
|
2023-11-19 21:07:48 +01:00
|
|
|
messagebox.showinfo("help", """Hilfe:
|
2023-10-21 22:10:11 +02:00
|
|
|
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():
|
2023-11-19 21:07:48 +01:00
|
|
|
messagebox.showinfo("sicherheit","""Zur Sicherheit:
|
2023-10-21 22:10:11 +02:00
|
|
|
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():
|
2023-11-19 21:07:48 +01:00
|
|
|
messagebox.showinfo("Debug",f"""Debug Informationen:
|
2023-10-21 22:10:11 +02:00
|
|
|
n_path={n_path}
|
|
|
|
pas_hash={passwort}""")
|
|
|
|
|
|
|
|
## variablen
|
2023-11-20 21:44:11 +01:00
|
|
|
passwort = "HALIHALLO"
|
2023-10-21 22:10:11 +02:00
|
|
|
##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}")
|
2023-11-19 21:07:48 +01:00
|
|
|
messagebox.showinfo("Verzeichniss","Notizenverzeichniss angelegt.")
|
2023-10-21 22:10:11 +02:00
|
|
|
n_path += "n"+tzeichen
|
|
|
|
|
2023-11-20 21:44:11 +01:00
|
|
|
#eigene_dialoge.notiz_auswahl()
|
|
|
|
#exit()
|
2023-10-21 22:10:11 +02:00
|
|
|
# Welcome screen
|
2023-11-20 20:20:46 +01:00
|
|
|
passwort = eigene_fenster.welcome_w()
|
2023-10-21 22:10:11 +02:00
|
|
|
# main fenster
|
2023-11-20 20:20:46 +01:00
|
|
|
eigene_fenster.main()
|