def make_hs_circuit(qubits, oracle_f, shift):
    """Find the shift between two almost equivalent functions."""
    c = cirq.Circuit()

    # Initialize qubits.
    c.append([cirq.H.on_each(*qubits)])

    # Query oracle g: It is equivalent to that of f, shifted before and after:
    # Apply Shift:
    c.append([cirq.X.on_each([qubits[k] for k in range(len(shift)) if shift[k]])])

    # Query oracle.
    c.append(oracle_f)

    # Apply Shift:
    c.append([cirq.X.on_each([qubits[k] for k in range(len(shift)) if shift[k]])])

    # Second Application of Hadamards.
    c.append([cirq.H.on_each(*qubits)])

    # Query oracle f (this simplifies the phase).
    c.append(oracle_f)

    # Inverse Fourier Transform with Hadamards to go back to the shift state:
    c.append([cirq.H.on_each(*qubits)])

    # Measure the result.
    c.append(cirq.measure(*qubits, key='result'))

    return c
Find the shift between two almost equivalent functions.
examples/hidden_shift_algorithm.py