datennamen anpassen
This commit is contained in:
parent
02b0734f0e
commit
90ae1d77eb
3 changed files with 265 additions and 493 deletions
55
notizen_w/n.py
Normal file → Executable file
55
notizen_w/n.py
Normal file → Executable file
|
@ -1,7 +1,9 @@
|
||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
|
||||||
import hashlib, os
|
import hashlib, os
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
|
|
||||||
# from tkinter import ttk
|
# from tkinter import ttk
|
||||||
|
|
||||||
## funktionen
|
## funktionen
|
||||||
|
@ -13,18 +15,26 @@ def a_str(inp, leng):
|
||||||
elif len(inp) > leng:
|
elif len(inp) > leng:
|
||||||
inp = inp[:leng]
|
inp = inp[:leng]
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
|
|
||||||
def sha512(passwort):
|
def sha512(passwort):
|
||||||
sha512 = hashlib.sha512()
|
sha512 = hashlib.sha512()
|
||||||
sha512.update(passwort.encode())
|
sha512.update(passwort.encode())
|
||||||
return sha512.hexdigest()
|
return sha512.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def crypt(text, key_hash):
|
def crypt(text, key_hash):
|
||||||
key_hash = a_str(key_hash, len(text))
|
key_hash = a_str(key_hash, len(text))
|
||||||
crypted_text = ""
|
crypted_text = ""
|
||||||
for i in range(len(text)):
|
for i in range(len(text)):
|
||||||
crypted_text += chr(ord(text[i]) ^ ord(key_hash[i]))
|
crypted_text += chr(ord(text[i]) ^ ord(key_hash[i]))
|
||||||
return crypted_text
|
return crypted_text
|
||||||
|
|
||||||
|
|
||||||
def o(note, mode):
|
def o(note, mode):
|
||||||
return open(f"{n_path}{note}.txt", mode, encoding="utf-8")
|
return open(f"{n_path}{note}.txt", mode, encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
def nlist():
|
def nlist():
|
||||||
string = ""
|
string = ""
|
||||||
notizen = []
|
notizen = []
|
||||||
|
@ -41,6 +51,7 @@ def nlist():
|
||||||
datei.close()
|
datei.close()
|
||||||
return [string, notizen]
|
return [string, notizen]
|
||||||
|
|
||||||
|
|
||||||
def neditadd(notiz=str, text=str):
|
def neditadd(notiz=str, text=str):
|
||||||
if not notiz + ".txt" in os.listdir(n_path):
|
if not notiz + ".txt" in os.listdir(n_path):
|
||||||
if notiz + ".txt" in os.listdir(n_path):
|
if notiz + ".txt" in os.listdir(n_path):
|
||||||
|
@ -54,17 +65,22 @@ def neditadd(notiz=str,text=str):
|
||||||
datei.close()
|
datei.close()
|
||||||
return back
|
return back
|
||||||
|
|
||||||
|
|
||||||
class eigene_fenster:
|
class eigene_fenster:
|
||||||
def welcome_w():
|
def welcome_w():
|
||||||
w_welcome = tk.Tk()
|
w_welcome = tk.Tk()
|
||||||
w_welcome.title("Welcome zu n")
|
w_welcome.title("Welcome zu n")
|
||||||
w_welcome.geometry("450x300")
|
w_welcome.geometry("450x300")
|
||||||
|
|
||||||
def ok():
|
def ok():
|
||||||
global passwort
|
global passwort
|
||||||
passwort = l_wpassword.get()
|
passwort = l_wpassword.get()
|
||||||
passwort = sha512(passwort)
|
passwort = sha512(passwort)
|
||||||
w_welcome.destroy()
|
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
|
ACHTUNG: Falls du dein Passwort falsch eingibst überprüfe
|
||||||
erst ob deine Notizen richtig angezeigt werden sonnst falls
|
erst ob deine Notizen richtig angezeigt werden sonnst falls
|
||||||
du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
||||||
|
@ -72,7 +88,8 @@ du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
||||||
ACHTUNG: Es kann seine das einige Zeichen wie Umlaute falsch
|
ACHTUNG: Es kann seine das einige Zeichen wie Umlaute falsch
|
||||||
angezeigt werden können.
|
angezeigt werden können.
|
||||||
|
|
||||||
Passwort:""")
|
Passwort:""",
|
||||||
|
)
|
||||||
l_wpassword = tk.Entry(w_welcome)
|
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_wtext.pack()
|
||||||
|
@ -82,15 +99,17 @@ Passwort:""")
|
||||||
return passwort
|
return passwort
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
class actions():
|
class actions:
|
||||||
def edit():
|
def edit():
|
||||||
notiz = eigene_dialoge.notiz_auswahl()
|
notiz = eigene_dialoge.notiz_auswahl()
|
||||||
print("Notiz ausgewählt")
|
print("Notiz ausgewählt")
|
||||||
write_note = eigene_dialoge.notiz_dialog(notiz)
|
write_note = eigene_dialoge.notiz_dialog(notiz)
|
||||||
info = neditadd(write_note[0], write_note[1])
|
info = neditadd(write_note[0], write_note[1])
|
||||||
messagebox("Notiz", info)
|
messagebox("Notiz", info)
|
||||||
|
|
||||||
def new():
|
def new():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
w_main = tk.Tk()
|
w_main = tk.Tk()
|
||||||
w_main.title("n")
|
w_main.title("n")
|
||||||
w_main.geometry("800x600")
|
w_main.geometry("800x600")
|
||||||
|
@ -122,6 +141,7 @@ class eigene_dialoge:
|
||||||
def notiz_dialog(title):
|
def notiz_dialog(title):
|
||||||
notiz = o(title, "r")
|
notiz = o(title, "r")
|
||||||
notiz_dialog = tk.Tk()
|
notiz_dialog = tk.Tk()
|
||||||
|
|
||||||
def cancel():
|
def cancel():
|
||||||
global ret
|
global ret
|
||||||
|
|
||||||
|
@ -129,6 +149,7 @@ class eigene_dialoge:
|
||||||
ret.set([title, notiz.read()])
|
ret.set([title, notiz.read()])
|
||||||
notiz_dialog.destroy()
|
notiz_dialog.destroy()
|
||||||
print(ret.get())
|
print(ret.get())
|
||||||
|
|
||||||
def ok():
|
def ok():
|
||||||
global ret
|
global ret
|
||||||
|
|
||||||
|
@ -159,11 +180,13 @@ class eigene_dialoge:
|
||||||
lbutton_cancel.pack(fill="x")
|
lbutton_cancel.pack(fill="x")
|
||||||
notiz_dialog.mainloop()
|
notiz_dialog.mainloop()
|
||||||
return ret.get()
|
return ret.get()
|
||||||
|
|
||||||
def notiz_auswahl():
|
def notiz_auswahl():
|
||||||
def done():
|
def done():
|
||||||
global ret
|
global ret
|
||||||
ret = gewählt.get()
|
ret = gewählt.get()
|
||||||
auswahl.destroy()
|
auswahl.destroy()
|
||||||
|
|
||||||
auswahl = tk.Tk()
|
auswahl = tk.Tk()
|
||||||
gewählt = tk.StringVar(auswahl)
|
gewählt = tk.StringVar(auswahl)
|
||||||
gewählt.set("Notiz auswählen")
|
gewählt.set("Notiz auswählen")
|
||||||
|
@ -176,11 +199,15 @@ class eigene_dialoge:
|
||||||
auswahl.mainloop()
|
auswahl.mainloop()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class tkf:
|
class tkf:
|
||||||
def refresh_list():
|
def refresh_list():
|
||||||
notiz_list.set(nlist()[0])
|
notiz_list.set(nlist()[0])
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
messagebox.showinfo("help", """Hilfe:
|
messagebox.showinfo(
|
||||||
|
"help",
|
||||||
|
"""Hilfe:
|
||||||
edit = Bearbeite eine Notiz.
|
edit = Bearbeite eine Notiz.
|
||||||
read = Zeige eine Notiz an.
|
read = Zeige eine Notiz an.
|
||||||
add = Erstelle eine Notiz.
|
add = Erstelle eine Notiz.
|
||||||
|
@ -190,9 +217,13 @@ secure = Wie funktioniert die verschlüsselung.
|
||||||
debug = Zeigt Debug Infos.
|
debug = Zeigt Debug Infos.
|
||||||
exit = Beenden.
|
exit = Beenden.
|
||||||
|
|
||||||
Bei Fehlern Bitte an Megamichi melden.""")
|
Bei Fehlern Bitte an Megamichi melden.""",
|
||||||
|
)
|
||||||
|
|
||||||
def secure():
|
def secure():
|
||||||
messagebox.showinfo("sicherheit","""Zur Sicherheit:
|
messagebox.showinfo(
|
||||||
|
"sicherheit",
|
||||||
|
"""Zur Sicherheit:
|
||||||
Es wir ein SHA-512 Hash aus dein Passwort erstellt.
|
Es wir ein SHA-512 Hash aus dein Passwort erstellt.
|
||||||
Und mit deinen Notizen und den auf die richtige Länge
|
Und mit deinen Notizen und den auf die richtige Länge
|
||||||
angepassten Hash wir ein One-Time-Pad angewendet.
|
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.
|
du eine neue Notiz erstellst wird sie anderst verschlüsselt.
|
||||||
|
|
||||||
ACHTUNG: Es kann seine Das einige Zeichen wie Umlaute falsch
|
ACHTUNG: Es kann seine Das einige Zeichen wie Umlaute falsch
|
||||||
angezeigt werden können.""")
|
angezeigt werden können.""",
|
||||||
|
)
|
||||||
|
|
||||||
def debug():
|
def debug():
|
||||||
messagebox.showinfo("Debug",f"""Debug Informationen:
|
messagebox.showinfo(
|
||||||
|
"Debug",
|
||||||
|
f"""Debug Informationen:
|
||||||
n_path={n_path}
|
n_path={n_path}
|
||||||
pas_hash={passwort}""")
|
pas_hash={passwort}""",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
## variablen
|
## variablen
|
||||||
passwort = "HALIHALLO"
|
passwort = "HALIHALLO"
|
||||||
|
|
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