2018-12-14 21:05:24 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import hashlib
|
|
|
|
import random
|
|
|
|
import secrets
|
2018-12-15 23:43:19 +00:00
|
|
|
import os
|
2018-12-14 21:05:24 +00:00
|
|
|
|
|
|
|
# Az egyszeruseg kedveert, 1 tomb = 1 sor
|
|
|
|
|
2018-12-15 23:43:19 +00:00
|
|
|
blokklanc_file = os.getenv("HOME") + "/.blokklanc.pp"
|
|
|
|
|
2018-12-14 21:05:24 +00:00
|
|
|
# Eredet tomb letrehozasa ha nem letezik
|
2018-12-15 23:43:19 +00:00
|
|
|
if not os.path.exists(blokklanc_file):
|
2018-12-14 21:05:24 +00:00
|
|
|
# Genezis/eredet tomb letrehozasa randommal, hogy ha ugyan az is ket szoveg, soha ne ugyan az legyen a kimenetel
|
|
|
|
eredet = "Eredet."
|
|
|
|
erand = secrets.token_hex(64)
|
|
|
|
etomb_adat = eredet + erand
|
|
|
|
etomb_hash = hashlib.sha512(etomb_adat.encode('utf-8')).hexdigest()
|
|
|
|
print("Eredet tömb: " + str(etomb_adat) + '||' + etomb_hash)
|
|
|
|
# beirni eredetet
|
2018-12-15 23:43:19 +00:00
|
|
|
f = open(blokklanc_file,'w')
|
2018-12-14 21:05:24 +00:00
|
|
|
f.write(str(etomb_adat) + etomb_hash)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
# kiolvassa az utolso sort
|
|
|
|
def utolso_sor():
|
2018-12-15 23:43:19 +00:00
|
|
|
blokk_file = open(blokklanc_file,'r')
|
2018-12-14 21:05:24 +00:00
|
|
|
for sor in blokk_file:
|
|
|
|
fb_sor = sor
|
|
|
|
print("Utolsó tömb: " + fb_sor)
|
|
|
|
return fb_sor
|
|
|
|
|
|
|
|
# hozzaad egy uj tombot
|
|
|
|
def uj_tomb(tomb_adat):
|
|
|
|
utolso_tomb_hash = utolso_sor()
|
|
|
|
uj_tomb = hashlib.sha512(utolso_tomb_hash.encode('utf-8')).hexdigest() + '||' + tomb_adat + '||'
|
|
|
|
uj_tomb_hash = hashlib.sha512(uj_tomb.encode('utf-8')).hexdigest()
|
2018-12-15 23:43:19 +00:00
|
|
|
fu = open(blokklanc_file,'a')
|
2018-12-14 21:05:24 +00:00
|
|
|
fu.write('\n' + uj_tomb + uj_tomb_hash)
|
|
|
|
|
|
|
|
# ujraszamolja a blokklanc helyesseget
|
|
|
|
def teljes_lanc_ellenorzes():
|
|
|
|
pass
|
|
|
|
teljes_lanc_ellenorzes()
|
|
|
|
|
|
|
|
|
|
|
|
# Kovetkezo letrehozasa
|
|
|
|
jegyzet = input()
|
|
|
|
uj_tomb(jegyzet)
|
|
|
|
#print("Teszt: " + hashlib.sha512("teszt".encode('utf-8')).hexdigest())
|
|
|
|
|
|
|
|
# cut -d '|' -f 3 blokklanc.pp | egrep -v "^Eredet."
|