import numpy as np
import hashlib
from binascii import hexlify
# ============================================================
# 1. CAPTURA DE INTERFERÊNCIA RF
# ============================================================
def rf_noise(samples=1024):
# Simula ruído RF capturado pelo host
noise = np.random.normal(0, 1, samples)
return hashlib.sha256(noise.tobytes()).digest()
# ============================================================
# 2. BLOCO LINKADO (CHAIN)
# ============================================================
def linked_block(seed: bytes, previous_hash: bytes) -> bytes:
h = hashlib.sha256()
h.update(seed)
h.update(previous_hash)
return h.digest()
# ============================================================
# 3. HASH DE 3 DÍGITOS
# ============================================================
def short_hash(block_hash: bytes) -> str:
# converte para hex e reduz a 3 dígitos
return hexlify(block_hash).decode()[:3].upper()
# ============================================================
# 4. EXECUÇÃO
# ============================================================
# bloco inicial
rf_seed = rf_noise()
prev_hash = b"init"
# gera 5 blocos encadeados
for i in range(5):
block = linked_block(rf_seed, prev_hash)
h3 = short_hash(block)
print(f"Bloco {i+1}: Hash 3 dígitos = {h3}")
prev_hash = block




No comments:
Post a Comment