Saturday, August 8, 2026

Decode SHA256 Grover's algorithm high altitude script code

 import numpy as np

from qiskit import QuantumCircuit, Aer, execute


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

# 1. SHA-4 (versão reduzida para demonstração)

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


def sha4(x):

    # Função hash simples de 4 bits (exemplo didático)

    return format((3*x + 1) % 16, "04b")


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

# 2. Oracle SHA-4

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


def oracle_sha4(n, target_hash):

    qc = QuantumCircuit(n)

    for x in range(2**n):

        if sha4(x) == target_hash:

            bits = format(x, "0{}b".format(n))

            for i, b in enumerate(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(bits):

                if b == "0":

                    qc.x(i)

    return



No comments:

Decode SHA256 Grover's algorithm high altitude script code

 import numpy as np from qiskit import QuantumCircuit, Aer, execute # ============================================================ # 1. SHA-...