Sunday, August 9, 2026
Decryption Grover algorithm Sha256 part 4
import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.providers.aer.noise import NoiseModel, depolarizing_error, thermal_relaxation_error
# ============================================================
# 1. Difusão (Grover)
# ============================================================
def diffusion(qc, qubits):
qc.h(qubits)
qc.x(qubits)
qc.h(qubits[-1])
qc.mcx(qubits[:-1], qubits[-1])
qc.h(qubits[-1])
qc.x(qubits)
qc.h(qubits)
# ============================================================
# 2. Oracle para "decryption" (pré-imagem)
# ============================================================
def oracle_mark(qc, target):
n = qc.num_qubits
for i, bit in enumerate(target):
if bit == "0":
qc.x(i)
qc.h(n-1)
qc.mcx(list(range(n-1)), n-1)
qc.h(n-1)
for i, bit in enumerate(target):
if bit == "0":
qc.x(i)
# ============================================================
# 3. Grover automático
# ============================================================
def grover_circuit(n, target, iterations):
qc = QuantumCircuit(n, n)
qc.h(range(n))
for _ in range(iterations):
oracle_mark(qc, target)
diffusion(qc, range(n))
qc.measure(range(n), range(n))
return qc
# ============================================================
# 4. Hardware realista com ruído escalável
# ============================================================
def hardware_noise(scale):
noise = NoiseModel()
# Parâmetros realistas (Sycamore/Aspen/Heron)
T1 = 40e-6 / scale
T2 = 60e-6 / scale
gate_time = 50e-9
dep1 = depolarizing_error(0.0003 * scale, 1)
dep2 = depolarizing_error(0.008 * scale, 2)
thermal = thermal_relaxation_error(T1, T2, gate_time)
noise.add_all_qubit_quantum_error(thermal, ['x','h'])
noise.add_all_qubit_quantum_error(dep1, ['x','h'])
noise.add_all_qubit_quantum_error(dep2, ['cx'])
return noise
# ============================================================
# 5. Execução automática com ruído escalado
# ============================================================
def run_scaled_noise(qc, scales=[0.5, 1, 2, 3]):
backend = Aer.get_backend("qasm_simulator")
results = []
for s in scales:
noise = hardware_noise(s)
job = execute(qc, backend, noise_model=noise, shots=4096)
counts = job.result().get_counts()
results.append((s, counts))
return results
# ============================================================
# 6. Decode automático
# ============================================================
def decode(counts):
return max(counts, key=counts.get)
# ============================================================
# 7. ZNE automático (extrapolação linear)
# ============================================================
def ZNE(results):
probs = []
for scale, counts in results:
total = sum(counts.values())
marked = max(counts, key=counts.get)
probs.append((scale, counts[marked] / total))
# extrapolação linear simples
(s1, p1), (s2, p2) = probs[0], probs[1]
zne_estimate = p1 + (p1 - p2)
return zne_estimate
# ============================================================
# 8. Pipeline completo
# ============================================================
def grover_decrypt(n=5, target="10101", iterations=2):
qc = grover_circuit(n, target, iterations)
results = run_scaled_noise(qc)
print("\n--- Resultados por escala de ruído ---")
for scale, counts in results:
print(f"Ruído x{scale}: {counts}")
print("\n--- Decode automático por escala ---")
for scale, counts in results:
print(f"Ruído x{scale}: estado marcado = {decode(counts)}")
print("\n--- Estimativa ZNE (ruído zero) ---")
print(ZNE(results))
return results
# ============================================================
# 9. Execução
# ============================================================
grover_decrypt()
import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.providers.aer.noise import NoiseModel, depolarizing_error, thermal_relaxation_error
# ============================================================
# 1. SHA-256 reduzido (8 bits) para demonstração
# ============================================================
def sha256_reduced(x):
return format((13*x + 7) % 256, "08b")
# ============================================================
# 2. Oracle SHA-256 (pré-imagem)
# ============================================================
def oracle_sha256(qc, x_qubits, h_qubits, target_hash):
# Escreve target_hash nos qubits de hash
for i, bit in enumerate(target_hash):
if bit == "0":
qc.x(h_qubits[i])
# Compara h_qubits com target_hash
qc.mcx(h_qubits[:-1], h_qubits[-1])
# Desfaz escrita
for i, bit in enumerate(target_hash):
if bit == "0":
qc.x(h_qubits[i])
# ============================================================
# 3. Difusão (Grover)
# ============================================================
def diffusion(qc, qubits):
qc.h(qubits)
qc.x(qubits)
qc.h(qubits[-1])
qc.mcx(qubits[:-1], qubits[-1])
qc.h(qubits[-1])
qc.x(qubits)
qc.h(qubits)
# ============================================================
# 4. Grover + SHA-256
# ============================================================
def grover_sha256(n=8, target_hash="10110011", iterations=2):
qc = QuantumCircuit(2*n, n)
x = list(range(n))
h = list(range(n, 2*n))
# Superposição inicial
qc.h(x)
# SHA-256 reversível reduzido
qc.cx(x, h)
# Iterações de Grover
for _ in range(iterations):
oracle_sha256(qc, x, h, target_hash)
diffusion(qc, x)
qc.measure(x, range(n))
return qc
# ============================================================
# 5. Hardware realista com ruído escalável
# ============================================================
def hardware_noise(scale):
noise = NoiseModel()
T1 = 40e-6 / scale
T2 = 60e-6 / scale
gate_time = 50e-9
dep1 = depolarizing_error(0.0003 * scale, 1)
dep2 = depolarizing_error(0.008 * scale, 2)
thermal = thermal_relaxation_error(T1, T2, gate_time)
noise.add_all_qubit_quantum_error(thermal, ['x','h'])
noise.add_all_qubit_quantum_error(dep1, ['x','h'])
noise.add_all_qubit_quantum_error(dep2, ['cx'])
return noise
# ============================================================
# 6. Execução automática com ruído escalado
# ============================================================
def run_scaled_noise(qc, scales=[0.5, 1, 2, 3]):
backend = Aer.get_backend("qasm_simulator")
results = []
for s in scales:
noise = hardware_noise(s)
job = execute(qc, backend, noise_model=noise, shots=4096)
counts = job.result().get_counts()
results.append((s, counts))
return results
# ============================================================
# 7. Decode automático
# ============================================================
def decode(counts):
return max(counts, key=counts.get)
# ============================================================
# 8. ZNE automático
# ============================================================
def ZNE(results):
probs = []
for scale, counts in results:
total = sum(counts.values())
marked = max(counts, key=counts.get)
probs.append((scale, counts[marked] / total))
(s1, p1), (s2, p2) = probs[0], probs[1]
zne_estimate = p1 + (p1 - p2)
return zne_estimate
# ============================================================
# 9. Pipeline completo
# ============================================================
def decrypt_sha256(target_hash="10110011"):
qc = grover_sha256(target_hash=target_hash)
results = run_scaled_noise(qc)
print("\n--- Resultados por escala de ruído ---")
for scale, counts in results:
print(f"Ruído x{scale}: {counts}")
print("\n--- Decode automático por escala ---")
for scale, counts in results:
print(f"Ruído x{scale}: pré-imagem = {decode(counts)}")
print("\n--- Estimativa ZNE (ruído zero) ---")
print(ZNE(results))
return results
# ============================================================
# 10. Execução
# ============================================================
decrypt_sha256()
Alternative to IBM Heron hardware ( grover algorithm high altitude scale noise adaptive decrypt SHA256)
from qiskit.providers.aer.noise import NoiseModel, thermal_relaxation_error, depolarizing_error
def noise_sycamore(scale):
noise = NoiseModel()
T1 = 25e-6 / scale
T2 = 35e-6 / scale
gate_time = 20e-9
dep1 = depolarizing_error(0.0001 * scale, 1)
dep2 = depolarizing_error(0.006 * scale, 2)
thermal = thermal_relaxation_error(T1, T2, gate_time)
noise.add_all_qubit_quantum_error(thermal, ['x','h'])
noise.add_all_qubit_quantum_error(dep1, ['x','h'])
noise.add_all_qubit_quantum_error(dep2, ['cx'])
return noise
def noise_aspen(scale):
noise = NoiseModel()
T1 = 40e-6 / scale
T2 = 50e-6 / scale
gate_time = 100e-9
dep1 = depolarizing_error(0.0002 * scale, 1)
dep2 = depolarizing_error(0.01 * scale, 2)
thermal = thermal_relaxation_error(T1, T2, gate_time)
noise.add_all_qubit_quantum_error(thermal, ['x','h'])
noise.add_all_qubit_quantum_error(dep1, ['x','h'])
noise.add_all_qubit_quantum_error(dep2, ['cx'])
return noise
def noise_ionq(scale):
noise = NoiseModel()
T1 = 1e9 # praticamente infinito
T2 = 1.0 # 1 segundo
gate_time = 200e-6
dep1 = depolarizing_error(0.000001 * scale, 1)
dep2 = depolarizing_error(0.001 * scale, 2)
thermal = thermal_relaxation_error(T1, T2, gate_time)
noise.add_all_qubit_quantum_error(thermal, ['x','h'])
noise.add_all_qubit_quantum_error(dep1, ['x','h'])
noise.add_all_qubit_quantum_error(dep2, ['cx'])
return noise
My attack prepare prepara máquina( elsa) injection prompt machine complie
python -m pip install --upgrade pip setuptools wheel pip install cython winget install Rustlang.Rustup rustup default stable pip install m...























































