Az első blokklánc kódom.
commit
ee48bd3efe
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/python3
|
||||
import hashlib
|
||||
import random
|
||||
import secrets
|
||||
import os.path
|
||||
|
||||
# Az egyszeruseg kedveert, 1 tomb = 1 sor
|
||||
|
||||
# Eredet tomb letrehozasa ha nem letezik
|
||||
if not os.path.exists("blokklanc.pp"):
|
||||
# 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
|
||||
f = open('blokklanc.pp','w')
|
||||
f.write(str(etomb_adat) + etomb_hash)
|
||||
f.close()
|
||||
|
||||
|
||||
# kiolvassa az utolso sort
|
||||
def utolso_sor():
|
||||
blokk_file = open('blokklanc.pp','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.pp','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()
|
||||
uj_tomb(jegyzet)
|
||||
#print("Teszt: " + hashlib.sha512("teszt".encode('utf-8')).hexdigest())
|
||||
|
||||
# cut -d '|' -f 3 blokklanc.pp | egrep -v "^Eredet."
|
|
@ -0,0 +1,3 @@
|
|||
Eredet.15c6cd96136e173c8e060629ba780b5287523004fcbd144ebf8acbe427170dd2c0b1f5838a336e93d28f741bf9b1976140bd4ae64257fa823060f0392e453bd03ebe6a34949d07877fef62bcfbfa9d23afaccbec655134b83ad1a3e6f42fc5871f29ae8b74175982cb1a77a43d7f0f96b349ab92f99a995e956907329aeed496
|
||||
8591471a4f7638c9fdc719b27f1bf53b4b6117a090f5ebf4faa1d66b34c4c21440dd3c21d42673fc1319bada07ef9f43ad20754e2d708b913becf3c4d8e96761||Ethereum whitepapert elolvastam, 2018.12.14.||dc8ab93563dd51fd1c91cb8795a82dc122feedbc9a64e71f23206e3917d3ab5411f3168b11a90f54f4e8c670f9bd8b66e21bdb4d26e15e2359437fb0a27f6c19
|
||||
625a8b5e339c41bdce708dda3dff62e22836b3775eb8e46f5614087fa35ffc4711d16c1e3c36a59a62bc3f19ea6f3af95f36afa042abdda34afb60f36cf45971||Letrehoztam az elso sajat blokklanc kodomat. Most ebbe a blokklancba jegyzetelek. 2018.12.14.||9d8028c7ed47a164088d1a9c67d5133de1fee71efc46632a93fedc44f00460089299cf6731ea9c6f7eb3ea770652f9aec05373669da3f90faa566e3ff52c4944
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import hashlib
|
||||
csekk = input()
|
||||
print("Teszteredmeny: " + hashlib.sha512(csekk.encode('utf-8')).hexdigest())
|
|
@ -0,0 +1,46 @@
|
|||
"""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')
|
||||
|
Loading…
Reference in New Issue