datennamen anpassen
This commit is contained in:
parent
02b0734f0e
commit
90ae1d77eb
3 changed files with 265 additions and 493 deletions
111
notizen_w/n.py
Normal file → Executable file
111
notizen_w/n.py
Normal file → Executable file
|
@ -1,8 +1,10 @@
|
|||
#!/bin/python3
|
||||
import hashlib,os
|
||||
|
||||
import hashlib, os
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
#from tkinter import ttk
|
||||
|
||||
# from tkinter import ttk
|
||||
|
||||
## funktionen
|
||||
def a_str(inp, leng):
|
||||
|
@ -13,18 +15,26 @@ def a_str(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))
|
||||
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 o(note, mode):
|
||||
return open(f"{n_path}{note}.txt", mode, encoding="utf-8")
|
||||
|
||||
|
||||
def nlist():
|
||||
string = ""
|
||||
notizen = []
|
||||
|
@ -36,35 +46,41 @@ def nlist():
|
|||
notizen.append(f"{a}"[:-4])
|
||||
for n in notizen:
|
||||
string += f" - {n}:\n"
|
||||
datei = o(n,"r")
|
||||
string += crypt(datei.read() ,passwort)+"\n"
|
||||
datei = o(n, "r")
|
||||
string += crypt(datei.read(), passwort) + "\n"
|
||||
datei.close()
|
||||
return [string,notizen]
|
||||
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):
|
||||
|
||||
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 = 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="""
|
||||
|
||||
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.
|
||||
|
@ -72,9 +88,10 @@ 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:""")
|
||||
Passwort:""",
|
||||
)
|
||||
l_wpassword = tk.Entry(w_welcome)
|
||||
l_wbutton = tk.Button(w_welcome, text="Start" ,command=ok)
|
||||
l_wbutton = tk.Button(w_welcome, text="Start", command=ok)
|
||||
l_wtext.pack()
|
||||
l_wpassword.pack()
|
||||
l_wbutton.pack(fill="x")
|
||||
|
@ -82,15 +99,17 @@ Passwort:""")
|
|||
return passwort
|
||||
|
||||
def main():
|
||||
class actions():
|
||||
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)
|
||||
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")
|
||||
|
@ -103,7 +122,7 @@ Passwort:""")
|
|||
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)
|
||||
# nmenu.add_command(label="delete", command=tkf.nlist)
|
||||
|
||||
moremenu = tk.Menu(menu, tearoff=0)
|
||||
menu.add_cascade(label="more", menu=moremenu)
|
||||
|
@ -120,33 +139,35 @@ Passwort:""")
|
|||
|
||||
class eigene_dialoge:
|
||||
def notiz_dialog(title):
|
||||
notiz = o(title,"r")
|
||||
notiz = o(title, "r")
|
||||
notiz_dialog = tk.Tk()
|
||||
|
||||
def cancel():
|
||||
global ret
|
||||
|
||||
ret = tk.StringVar(notiz_dialog)
|
||||
ret.set([title,notiz.read()])
|
||||
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()])
|
||||
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)
|
||||
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)
|
||||
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()
|
||||
|
@ -159,11 +180,13 @@ class eigene_dialoge:
|
|||
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")
|
||||
|
@ -171,16 +194,20 @@ class eigene_dialoge:
|
|||
tauswahl.pack()
|
||||
dropdown = tk.OptionMenu(auswahl, gewählt, *nlist()[1])
|
||||
dropdown.pack()
|
||||
button = tk.Button(auswahl,text="Auswählen",command=done)
|
||||
button = tk.Button(auswahl, text="Auswählen", command=done)
|
||||
button.pack(fill="x")
|
||||
auswahl.mainloop()
|
||||
return ret
|
||||
|
||||
class tkf :
|
||||
|
||||
class tkf:
|
||||
def refresh_list():
|
||||
notiz_list.set(nlist()[0])
|
||||
|
||||
def help():
|
||||
messagebox.showinfo("help", """Hilfe:
|
||||
messagebox.showinfo(
|
||||
"help",
|
||||
"""Hilfe:
|
||||
edit = Bearbeite eine Notiz.
|
||||
read = Zeige eine Notiz an.
|
||||
add = Erstelle eine Notiz.
|
||||
|
@ -190,9 +217,13 @@ secure = Wie funktioniert die verschlüsselung.
|
|||
debug = Zeigt Debug Infos.
|
||||
exit = Beenden.
|
||||
|
||||
Bei Fehlern Bitte an Megamichi melden.""")
|
||||
Bei Fehlern Bitte an Megamichi melden.""",
|
||||
)
|
||||
|
||||
def secure():
|
||||
messagebox.showinfo("sicherheit","""Zur Sicherheit:
|
||||
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.
|
||||
|
@ -202,11 +233,17 @@ 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.""")
|
||||
angezeigt werden können.""",
|
||||
)
|
||||
|
||||
def debug():
|
||||
messagebox.showinfo("Debug",f"""Debug Informationen:
|
||||
messagebox.showinfo(
|
||||
"Debug",
|
||||
f"""Debug Informationen:
|
||||
n_path={n_path}
|
||||
pas_hash={passwort}""")
|
||||
pas_hash={passwort}""",
|
||||
)
|
||||
|
||||
|
||||
## variablen
|
||||
passwort = "HALIHALLO"
|
||||
|
@ -216,11 +253,11 @@ 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
|
||||
messagebox.showinfo("Verzeichniss", "Notizenverzeichniss angelegt.")
|
||||
n_path += "n" + tzeichen
|
||||
|
||||
eigene_dialoge.notiz_dialog("dodel")
|
||||
#eigene_dialoge.notiz_auswahl()
|
||||
# eigene_dialoge.notiz_auswahl()
|
||||
exit()
|
||||
# Welcome screen
|
||||
passwort = eigene_fenster.welcome_w()
|
||||
|
|
265
notizen_w/nv2.py
265
notizen_w/nv2.py
|
@ -1,265 +0,0 @@
|
|||
#!/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()
|
Loading…
Reference in a new issue