#!/usr/bin/python3 import hashlib import random import sys ## That part was originally secrets.py --> now bcp is integrated into a single file program """Generate cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar. See PEP 506 for more information. https://www.python.org/dev/peps/pep-0506/ Amit nem hasznalok belole azt kivettem! Eredeti forras: https://raw.githubusercontent.com/python/cpython/3.7/Lib/secrets.py """ __all__ = ['choice', 'randbelow', 'randbits', 'SystemRandom', 'token_bytes', 'token_hex', 'token_urlsafe', 'compare_digest', ] import base64 import binascii import os from hmac import compare_digest from random import SystemRandom _sysrand = SystemRandom() randbits = _sysrand.getrandbits choice = _sysrand.choice DEFAULT_ENTROPY = 64 # number of bytes to return by default def token_bytes(nbytes=None): """Return a random byte string containing *nbytes* bytes. >>> token_bytes(16) #doctest:+SKIP b'\\xebr\\x17D*t\\xae\\xd4\\xe3S\\xb6\\xe2\\xebP1\\x8b'""" if nbytes is None: nbytes = DEFAULT_ENTROPY return os.urandom(nbytes) def token_hex(nbytes=None): """Return a random text string, in hexadecimal. >>> token_hex(16) #doctest:+SKIP 'f9bf78b9a18ce6d46a0cd2b0b86df9da'""" return binascii.hexlify(token_bytes(nbytes)).decode('ascii') ## End of integrated secrets.py # Az egyszeruseg kedveert, 1 tomb = 1 sor blokklanc_file = os.getenv("HOME") + "/.blokklanc.pp" # Eredet tomb letrehozasa ha nem letezik if not os.path.exists(blokklanc_file): # Genezis/eredet tomb letrehozasa randommal, hogy ha ugyan az is ket szoveg, soha ne ugyan az legyen a kimenetel eredet = "Eredet." erand = token_hex(64) etomb_adat = eredet + erand etomb_hash = hashlib.sha512(etomb_adat.encode('utf-8')).hexdigest() print("Initializing...") print("Origin block: " + str(etomb_adat) + '||' + etomb_hash) # beirni eredetet ask_for_write = input("Save the first block into " + blokklanc_file + "? [y/n] ") if ask_for_write != "y": sys.exit() f = open(blokklanc_file,'w') f.write(str(etomb_adat) + etomb_hash) f.close() # kiolvassa az utolso sort def utolso_sor(): blokk_file = open(blokklanc_file,'r') 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() fu = open(blokklanc_file,'a') fu.write('\n' + uj_tomb + uj_tomb_hash) # ujraszamolja a blokklanc helyesseget def teljes_lanc_ellenorzes(): pass teljes_lanc_ellenorzes() # Kovetkezo letrehozasa jegyzet = input("What do you want to add to the blockchain? ") uj_tomb(jegyzet) #print("Teszt: " + hashlib.sha512("teszt".encode('utf-8')).hexdigest()) # cut -d '|' -f 3 blokklanc.pp | egrep -v "^Eredet."