Sunday, August 9, 2026

Decrypt SHA256 cryogenic issues ( high altitude attempt tentativa de desincriptação em aviões) productos chip electrónica e integrado circuito quantum militar

 






































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()






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()







import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.providers.aer.noise import NoiseModel, depolarizing_error

# ============================================================
# 1. Converter imagem → bits → qubits
# ============================================================

def image_to_bits(img):
    flat = img.flatten()
    bits = "".join([format(p, "08b") for p in flat])
    return bits

# ============================================================
# 2. Permutação reversível (encriptação)
# ============================================================

def encrypt_bits(bits, perm):
    return "".join(bits[i] for i in perm)

# ============================================================
# 3. Oracle para desincriptação da imagem
# ============================================================

def oracle_image(qc, target_bits):
    n = len(target_bits)
    for i, b in enumerate(target_bits):
        if b == "0":
            qc.x(i)

    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)

    for i, b in enumerate(target_bits):
        if b == "0":
            qc.x(i)

# ============================================================
# 4. 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)

# ============================================================
# 5. Grover para desincriptação da imagem
# ============================================================

def grover_decrypt_image(bits, encrypted_bits, iterations=2):
    n = len(bits)
    qc = QuantumCircuit(n, n)

    # Superposição inicial
    qc.h(range(n))

    # Oracle marca o estado da imagem original
    for _ in range(iterations):
        oracle_image(qc, bits)
        diffusion(qc, range(n))

    qc.measure(range(n), range(n))
    return qc

# ============================================================
# 6. Ruído realista escalável
# ============================================================

def scalable_noise(scale):
    noise = NoiseModel()
    dep = depolarizing_error(0.01 * scale, 1)
    noise.add_all_qubit_quantum_error(dep, ['x','h'])
    return noise

# ============================================================
# 7. Execução + decode
# ============================================================

def run_decrypt(qc):
    backend = Aer.get_backend("qasm_simulator")
    job = execute(qc, backend, shots=4096)
    counts = job.result().get_counts()
    return max(counts, key=counts.get)

# ============================================================
# 8. Pipeline completo
# ============================================================

def quantum_image_decrypt(img):
    bits = image_to_bits(img)

    # permutação aleatória (encriptação)
    perm = np.random.permutation(len(bits))
    encrypted_bits = encrypt_bits(bits, perm)

    qc = grover_decrypt_image(bits, encrypted_bits)
    recovered = run_decrypt(qc)

    return recovered






import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.providers.aer.noise import NoiseModel, depolarizing_error

# ============================================================
# 1. Lorenz 3D chaotic system
# ============================================================

def lorenz_3d(n, dt=0.01, sigma=10, rho=28, beta=8/3):
    x, y, z = 0.1, 0.0, 0.0
    seq = []

    for _ in range(n):
        dx = sigma * (y - x)
        dy = x * (rho - z) - y
        dz = x * y - beta * z

        x += dx * dt
        y += dy * dt
        z += dz * dt

        seq.append(abs(x + y + z))

    return np.array(seq)

# ============================================================
# 2. Image → bits
# ============================================================

def image_to_bits(img):
    flat = img.flatten()
    bits = "".join([format(p, "08b") for p in flat])
    return bits

# ============================================================
# 3. Encrypt image using 3D chaos
# ============================================================

def encrypt_with_chaos(bits):
    n = len(bits)
    chaos = lorenz_3d(n)

    # Permutation
    perm = np.argsort(chaos)
    permuted = "".join(bits[i] for i in perm)

    # Diffusion (XOR with chaotic sequence)
    chaotic_bits = "".join("1" if c % 2 > 1 else "0" for c in chaos)
    diffused = "".join("1" if permuted[i] != chaotic_bits[i] else "0" for i in range(n))

    return diffused, perm

# ============================================================
# 4. Oracle for image decryption
# ============================================================

def oracle_image(qc, target_bits):
    n = len(target_bits)
    for i, b in enumerate(target_bits):
        if b == "0":
            qc.x(i)

    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)

    for i, b in enumerate(target_bits):
        if b == "0":
            qc.x(i)

# ============================================================
# 5. Grover iteration
# ============================================================

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)

# ============================================================
# 6. Grover circuit for image decryption
# ============================================================

def grover_decrypt_image(bits, encrypted_bits, iterations=2):
    n = len(bits)
    qc = QuantumCircuit(n, n)

    qc.h(range(n))

    for _ in range(iterations):
        oracle_image(qc, bits)
        diffusion(qc, range(n))

    qc.measure(range(n), range(n))
    return qc

# ============================================================
# 7. Noise model (realistic)
# ============================================================

def scalable_noise(scale):
    noise = NoiseModel()
    dep = depolarizing_error(0.01 * scale, 1)
    noise.add_all_qubit_quantum_error(dep, ['x','h'])
    return noise

# ============================================================
# 8. Execute + decode
# ============================================================

def run_decrypt(qc):
    backend = Aer.get_backend("qasm_simulator")
    job = execute(qc, backend, shots=4096)
    counts = job.result().get_counts()
    return max(counts, key=counts.get)

# ============================================================
# 9. Full pipeline
# ============================================================

def quantum_image_decrypt(img):
    bits = image_to_bits(img)
    encrypted_bits, perm = encrypt_with_chaos(bits)

    qc = grover_decrypt_image(bits, encrypted_bits)
    recovered = run_decrypt(qc)

    return recovered

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










Noise high altitude decrypt ( also ideal decode )Grover algorithm Sha256 part 2



 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 simples (pode ser substituído por SHA-256)

# ============================================================


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. Modelo de ruído escalável

# ============================================================


def scalable_noise(scale):

    noise = NoiseModel()


    # Parâmetros base (podem ser substituídos por IBM Heron)

    T1 = 100e-6 / scale

    T2 = 80e-6 / scale

    gate_time = 50e-9


    thermal = thermal_relaxation_error(T1, T2, gate_time)

    dep1 = depolarizing_error(0.001 * scale, 1)

    dep2 = depolarizing_error(0.01 * scale, 2)


    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 = scalable_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_noise_decode(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_noise_decode()






















import numpy as np

from qiskit import QuantumCircuit, Aer, execute

from qiskit.providers.aer.noise import NoiseModel, thermal_relaxation_error, depolarizing_error


# ============================================================

# 1. Ruído de altitude

# ============================================================


def noise_altitude(temp_celsius):

    base_T1 = 80e-6

    base_T2 = 60e-6

    factor = max(0.2, min(2.0, (25 - temp_celsius) / 25))

    T1 = base_T1 * factor

    T2 = base_T2 * factor


    noise = NoiseModel()

    thermal = thermal_relaxation_error(T1, T2, 50e-9)

    em = depolarizing_error(0.02, 1)

    vib = depolarizing_error(0.01, 1)


    noise.add_all_qubit_quantum_error(thermal, ['x','h'])

    noise.add_all_qubit_quantum_error(em, ['cx'])

    noise.add_all_qubit_quantum_error(vib, ['h'])

    return noise


# ============================================================

# 2. SHA-256 reversível ideal (placeholder)

# ============================================================


def SHA256_reversible(qc, x_qubits, h_qubits):

    qc.cx(x_qubits, h_qubits)


# ============================================================

# 3. Oracle SHA-256

# ============================================================


def oracle_SHA256(qc, x_qubits, h_qubits, target_hash):

    for i, bit in enumerate(target_hash):

        if bit == "0":

            qc.x(h_qubits[i])

    qc.mcx(h_qubits[:-1], h_qubits[-1])

    for i, bit in enumerate(target_hash):

        if bit == "0":

            qc.x(h_qubits[i])


# ============================================================

# 4. Difusão

# ============================================================


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)


# ============================================================

# 5. Grover + ruído de altitude

# ============================================================


def grover_SHA256_altitude(n=8, target_hash="10110011", iterations=2, temp=-60):

    qc = QuantumCircuit(2*n, n)


    x = list(range(n))

    h = list(range(n, 2*n))


    qc.h(x)

    SHA256_reversible(qc, x, h)


    for _ in range(iterations):

        oracle_SHA256(qc, x, h, target_hash)

        diffusion(qc, x)


    qc.measure(x, range(n))


    backend = Aer.get_backend("qasm_simulator")

    noise = noise_altitude(temp)

    result = execute(qc, backend, noise_model=noise, shots=4096).result()

    return result.get_counts()


# ============================================================

# 6. Decode sob ruído

# ============================================================


def decode_noisy(counts):

    return max(counts, key=counts.get)


# ============================================================

# 7. Execução

# ============================================================


counts = grover_SHA256_altitude()

print("Counts:", counts)

print("Pré-imagem encontrada:", decode_noisy(counts))

from qiskit.providers.aer.noise import NoiseModel, thermal_relaxation_error, depolarizing_error


def noise_ibm_heron():

    noise = NoiseModel()


    # Coerência realista

    T1 = 120e-6

    T2 = 90e-6

    gate_time = 80e-9


    # Erros realistas

    err_1q = 0.0005

    err_2q = 0.005


    thermal = thermal_relaxation_error(T1, T2, gate_time)

    dep1 = depolarizing_error(err_1q, 1)

    dep2 = depolarizing_error(err_2q, 2)


    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 ZNE(qc, noise_fn):

    backend = Aer.get_backend("qasm_simulator")

    scales = [0.5, 1, 2, 3]

    results = []


    for s in scales:

        noise = noise_fn(s)

        job = execute(qc, backend, noise_model=noise, shots=4096)

        results.append(job.result().get_counts())


    # Extrapolação linear simples

    probs = [res.get(max(res, key=res.get), 0)/4096 for res in results]

    zne_estimate = probs[0] + (probs[0] - probs[1])  # extrapolação linear


    return zne_estimate

def PEC_correct(counts, error_rate=0.005):

    corrected = {}

    for state, c in counts.items():

        corrected[state] = c * (1 + error_rate)

    return corrected

def CDR_predict(counts):

    # Regressão linear conceptual

    total = sum(counts.values())

    probs = {k: v/total for k, v in counts.items()}

    return max(probs, key=probs.get)

def grover_SHA256_ibm(n=8, target_hash="10110011", iterations=2):

    qc = QuantumCircuit(2*n, n)


    x = list(range(n))

    h = list(range(n, 2*n))


    qc.h(x)

    SHA256_reversible(qc, x, h)


    for _ in range(iterations):

        oracle_SHA256(qc, x, h, target_hash)

        diffusion(qc, x)


    qc.measure(x, range(n))

    return qc


# Execução

qc = grover_SHA256_ibm()


backend = Aer.get_backend("qasm_simulator")

noise = noise_ibm_heron()


result = execute(qc, backend, noise_model=noise, shots=4096).result()

counts = result.get_counts()


# Mitigação

zne = ZNE(qc, lambda s: noise_ibm_heron())

pec = PEC_correct(counts)

cdr = CDR_predict(counts)


print("Counts brutos:", counts)

print("ZNE:", zne)

print("PEC:", pec)

print("CDR:", cdr)

from qiskit import QuantumCircuit, Aer, execute


# ============================================================

# 1. SHA-256 reversível ideal (abstração)

# ============================================================


def SHA256_reversible(qc, x_qubits, h_qubits):

    # Representação ideal: copia x → h

    # Em hardware real isto seria o circuito completo SHA-256 reversível

    qc.cx(x_qubits, h_qubits)


# ============================================================

# 2. Oracle ideal para SHA-256

# ============================================================


def oracle_SHA256(qc, x_qubits, h_qubits, target_hash):

    for i, bit in enumerate(target_hash):

        if bit == "0":

            qc.x(h_qubits[i])


    qc.mcx(h_qubits[:-1], h_qubits[-1])


    for i, bit in enumerate(target_hash):

        if bit == "0":

            qc.x(h_qubits[i])


# ============================================================

# 3. Difusão ideal

# ============================================================


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 ideal para SHA-256

# ============================================================


def grover_SHA256(n=256, target_hash="0"*256, iterations=2):

    qc = QuantumCircuit(2*n, n)


    x = list(range(n))

    h = list(range(n, 2*n))


    qc.h(x)

    SHA256_reversible(qc, x, h)


    for _ in range(iterations):

        oracle_SHA256(qc, x, h, target_hash)

        diffusion(qc, x)


    qc.measure(x, range(n))

    return qc


# ============================================================

# 5. Decode ideal

# ============================================================


def decode(counts):

    return max(counts, key=counts.get)


# ============================================================

# 6. Execução ideal

# ============================================================


backend = Aer.get_backend("qasm_simulator")

qc = grover_SHA256(n=8, target_hash="10110011")  # versão reduzida para teste

result = execute(qc, backend, shots=4096).result()

counts = result.get_counts()


print("Counts:", counts)

print("Pré-imagem encontrada:", decode(counts))




António Costa Portugal Intel SIRESP equipamento ( 5x mais caro )

 https://jornaleconomico.sapo.pt/noticias/siresp-12-anos-de-suspeitas-e-falhancos-174913/#goog_rewarded https://www.jornaldenegocios.pt/empr...