first commit
This commit is contained in:
commit
478d310030
2 changed files with 385 additions and 0 deletions
132
notizen/n.py
Normal file
132
notizen/n.py
Normal file
|
@ -0,0 +1,132 @@
|
|||
import hashlib,os
|
||||
|
||||
## 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():
|
||||
if os.listdir(n_path) == []:
|
||||
print("Noch keine Notizen")
|
||||
else:
|
||||
print("Deine Notizen:")
|
||||
for a in os.listdir(n_path):
|
||||
print(f" - {a}"[:-4])
|
||||
|
||||
## variablen
|
||||
passwort = input("Passwort:")
|
||||
passwort = sha512(passwort)
|
||||
|
||||
##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}")
|
||||
print("Notizenverzeichniss angelegt.")
|
||||
n_path += "n"+tzeichen
|
||||
|
||||
## start
|
||||
print(""" Wikkommen zu n
|
||||
|
||||
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.
|
||||
|
||||
Was möchtest du machen?: add, edit, read, list, help, exit.
|
||||
""")
|
||||
nlist()
|
||||
|
||||
## programmschleife
|
||||
while 1:
|
||||
action = input(">")
|
||||
if action == "help": #help
|
||||
print("""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.""")
|
||||
if action == "secure": #secure
|
||||
print("""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.""")
|
||||
if action == "edit": #edit
|
||||
a_note = input("Notiz Titel:")
|
||||
if not a_note+".txt" in os.listdir(n_path):
|
||||
print("Notiz nicht gefunden es wird eine neue angelegt.")
|
||||
datei = o(a_note,"w")
|
||||
text = input("bitte neuen Text einfügen:")
|
||||
datei.write(crypt(text, passwort))
|
||||
datei.close
|
||||
print("Erfolgreich gespeichert")
|
||||
if action == "read": #read
|
||||
a_note = input("Notiz Titel:")
|
||||
if a_note+".txt" in os.listdir(n_path):
|
||||
datei = o(a_note,"r")
|
||||
print(crypt(datei.read() ,passwort))
|
||||
datei.close
|
||||
else:
|
||||
print("Notiz gibts nicht.")
|
||||
if action == "add": #add
|
||||
a_note = input("Notiz Titel:")
|
||||
if a_note+".txt" in os.listdir(n_path):
|
||||
print("Notiz gibt es schon.")
|
||||
else:
|
||||
datei = o(a_note,"w")
|
||||
text = input("bitte neuen Text einfügen:")
|
||||
datei.write(crypt(text , passwort))
|
||||
datei.close
|
||||
print("Erfolgreich gespeichert")
|
||||
if action == "delete": #delete
|
||||
a_note = input("Notiz Titel:")
|
||||
if a_note+".txt" in os.listdir(n_path):
|
||||
if input("Wirklich löschen?:") == "ja":
|
||||
os.remove(f"{n_path}{a_note}.txt")
|
||||
print("Notiz gelöscht")
|
||||
else:
|
||||
print("Notiz nicht gelöscht")
|
||||
else:
|
||||
print("Notiz gibt es nicht.")
|
||||
if action == "list": #list
|
||||
nlist()
|
||||
if action == "debug": #debug
|
||||
print(f"""Debug Informationen:
|
||||
n_path={n_path}
|
||||
pas_hash={passwort}""")
|
||||
if action == "exit": #exit
|
||||
print("Bye")
|
||||
exit()
|
Loading…
Add table
Add a link
Reference in a new issue