Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantum PIN Cracker

Scalable 2/3-Qubit Grover's Search & Overcooking Analysis with Azure Quantum QDK

Author: Yiğit Mert YILMAZ Microsoft Azure Quantum Q# Language Python 3.11 Complexity License: MIT

An educational and scalable quantum cryptanalysis suite developed by Yiğit Mert YILMAZ as part of the Microsoft AI Innovators Summer Internship Program (Quantum Programming Onboarding Track).


Live Interactive Demo · Directory Structure · System Architecture · Circuit Schematics · Results Report · Quickstart

Note

This project was engineered by Yiğit Mert YILMAZ for the Microsoft AI Innovators Summer Internship Program (Quantum Programming Onboarding Track). It implements a parameterized Grover's search algorithm, Hilbert space wave-function tomography, and empirical overcooking analysis on the Microsoft Azure Quantum QDK local simulator.


Table of Contents (Click to expand)

Problem Context and Quantum Cryptanalysis Motivation

In classical computing, finding a secret $N$-state key without structure requires evaluating candidates one by one via brute-force ($\mathcal{O}(N)$ queries):

┌───────────────────────────────────────────────────────────────────────────────────┐
│                       THE UNSTRUCTURED SEARCH BOTTLENECK                          │
│                                                                                   │
│  [CLASSICAL BRUTE-FORCE: O(N)]            [QUANTUM GROVER SEARCH: O(√N)]          │
│  • Sequential trial-and-error             • Parallel state superposition          │
│  • Average queries: (N + 1) / 2           • Optimal query bound: ~π/4 * √N        │
│  • N = 4  (2-bit): 2.50 queries           • N = 4  (2-bit): 1 query  (100.0%)     │
│  • N = 8  (3-bit): 4.50 queries           • N = 8  (3-bit): 2 queries (~94.5%)    │
│  • N = 256 (8-bit): ~128 queries          • N = 256 (8-bit): ~12 queries (10.7x)  │
└───────────────────────────────────────────────────────────────────────────────────┘

Quantum PIN Cracker maps the cryptographic search space onto quantum registers and applies Grover's Algorithm:

$$|\psi\rangle \xrightarrow{H^{\otimes n}} |s\rangle \xrightarrow{(D \cdot U_\omega)^R} |\omega\rangle$$

  • 2-Qubit Baseline ($N=4$): Solves the search in exactly 1 query with 100% certainty.
  • 3-Qubit Scaling ($N=8$): Solves the search in 2 queries with ~94.5% certainty, demonstrating quadratic quantum acceleration ($\mathcal{O}(\sqrt{N})$).

Project Directory Structure

ms-quantum-pin-cracker/
├── docs/
│   ├── assets/                          # 5 Publication-grade 300-DPI visual assets
│   │   ├── hilbert_space_rotation.png   # 2D Hilbert space vector rotation
│   │   ├── overcooking_curve.png        # Overcooking empirical vs theoretical curve
│   │   ├── quantum_vs_classical.png     # Classical vs Quantum query comparison
│   │   ├── scaling_complexity_curve.png # Asymptotic query growth (N=4 to N=256)
│   │   └── state_vector_evolution.png   # 4-stage amplitude distribution
│   └── results.md                       # Comprehensive laboratory benchmark report
├── scripts/
│   ├── azure_submission.py              # Azure Quantum Workspace cloud submission template
│   ├── generate_charts.py               # Visual chart generation script (300 DPI)
│   ├── interactive_cracker.py           # Live 60FPS wave-function visualizer & race engine
│   └── run_benchmark.py                 # Automated Monte Carlo & overcooking test runner
├── src/
│   ├── Main.qs                          # EntryPoint & statistical sweep loop
│   └── Operations.qs                    # Superposition, Oracle & Diffusion operators
├── .gitignore                           # Git ignore rules for Python, QDK, and build artifacts
├── LICENSE                              # MIT License
├── qsharp.json                          # Modern QDK project manifest
├── requirements.txt                     # Categorized Python dependencies
└── README.md                            # Primary documentation

System Architecture and Pipeline Design

┌────────────────────────────────────────────────────────────────────────────────────────┐
│                          MICROSOFT QUANTUM PIN CRACKER SUITE                           │
│                                                                                        │
│  [1] ORCHESTRATION LAYER (Python)      [2] QUANTUM CORE (Microsoft Q#)                 │
│  ┌─────────────────────────────────┐   ┌────────────────────────────────────────────┐  │
│  │ scripts/run_benchmark.py        │   │ src/Main.qs (@EntryPoint)                  │  │
│  │ (Monte Carlo & Sweep Runner)    │──>│ (Allocates Qubit[n], Manages Lifecycles)   │  │
│  ├─────────────────────────────────┤   ├────────────────────────────────────────────┤  │
│  │ scripts/interactive_cracker.py  │   │ src/Operations.qs                          │  │
│  │ (60FPS Tomography & Race Engine)│   │ • PrepareSuperposition (Hadamard Gates)    │  │
│  ├─────────────────────────────────┤   │ • MarkTargetPIN (X + Controlled Z Oracle)  │  │
│  │ scripts/generate_charts.py      │   │ • ApplyDiffusion (Inversion About Mean)    │  │
│  │ (5x Publication-Grade Assets)   │   │ • Safe Deallocation with ResetAll          │  │
│  ├─────────────────────────────────┤   └────────────────────────────────────────────┘  │
│  │ scripts/azure_submission.py     │                                                   │
│  │ (Azure Cloud QPU Dispatcher)    │                                                   │
│  └─────────────────────────────────┘                                                   │
└────────────────────────────────────────────────────────────────────────────────────────┘

Execution Pipeline

flowchart TD
    subgraph Host ["Python Orchestration Layer"]
        CLI["scripts/run_benchmark.py"]
        GUI["scripts/interactive_cracker.py"]
        Viz["scripts/generate_charts.py"]
        Cloud["scripts/azure_submission.py"]
    end

    subgraph QSharp ["Azure Quantum QDK Engine"]
        M["src/Main.qs (@EntryPoint)"]
        OP["src/Operations.qs"]
        
        subgraph Circuit ["Q# Unitary Operations"]
            SUP["PrepareSuperposition (H ⊗ n)"]
            ORA["MarkTargetPIN (X + Controlled-Z)"]
            DIF["ApplyDiffusion (2|s⟩⟨s| - I)"]
        end
    end

    subgraph Output ["Artifacts & Documentation"]
        RES["docs/results.md"]
        PNG["docs/assets/*.png (5x Charts)"]
    end

    CLI -->|Compiles & Executes| M
    GUI -->|Live Tomography| M
    M --> OP
    OP --> SUP --> ORA --> DIF
    CLI -->|Generates Data| RES
    Viz -->|Renders 300-DPI| PNG
    Cloud -.->|Optional Dispatch| AzureQ["Real Cloud QPU (IonQ / Rigetti)"]
Loading

Quantum Circuit Implementation

flowchart LR
    subgraph Inputs ["Registers"]
        q0["|q₀⟩ = |0⟩"]
        q1["|q₁⟩ = |0⟩"]
        q2["|q₂⟩ = |0⟩"]
    end

    subgraph Superpos ["1. Superposition"]
        H0["H"]
        H1["H"]
        H2["H"]
    end

    subgraph Oracle ["2. Oracle (e.g. Target |101⟩)"]
        X1_pre["X"]
        CZ["Controlled-Z"]
        X1_post["X"]
    end

    subgraph Diffusion ["3. Diffusion (Inversion about Mean)"]
        DH0["H"] --> DX0["X"] --> DCZ["Controlled-Z"] --> DX0_["X"] --> DH0_["H"]
        DH1["H"] --> DX1["X"] -.-> DCZ -.-> DX1_["X"] --> DH1_["H"]
        DH2["H"] --> DX2["X"] -.-> DCZ -.-> DX2_["X"] --> DH2_["H"]
    end

    subgraph Readout ["4. Measurement"]
        M0["M(q₀) ➔ Bit 0"]
        M1["M(q₁) ➔ Bit 1"]
        M2["M(q₂) ➔ Bit 2"]
    end

    q0 --> H0 --> Oracle
    q1 --> H1 --> X1_pre --> CZ --> X1_post --> Diffusion
    q2 --> H2 --> Oracle
    Diffusion --> Readout
Loading

1. Parameterized Phase Oracle (MarkTargetPIN3Qubits)

Unlike hardcoded solutions, our Oracle supports any arbitrary 3-bit PIN (000 through 111) via $X$-gate bit-conditioning and multi-controlled phase kickback:

operation MarkTargetPIN3Qubits(qubits : Qubit[], target : Bool[]) : Unit is Adj + Ctl {
    // 1. Bit-conditioning: flip qubits where the target bit is '0'
    for i in 0..2 {
        if not target[i] { X(qubits[i]); }
    }

    // 2. Multi-Controlled Z: inverts phase only when all control qubits are |1⟩
    Controlled Z([qubits[0], qubits[1]], qubits[2]);

    // 3. Uncomputation: restore basis states while retaining inverted phase
    for i in 0..2 {
        if not target[i] { X(qubits[i]); }
    }
}

2. Diffusion Operator (ApplyDiffusion3Qubits)

Reflects state amplitudes around the mean ($D = 2|s\rangle\langle s| - I$), boosting the target state while suppressing non-target states:

operation ApplyDiffusion3Qubits(qubits : Qubit[]) : Unit is Adj + Ctl {
    H(qubits[0]); H(qubits[1]); H(qubits[2]);
    X(qubits[0]); X(qubits[1]); X(qubits[2]);
    Controlled Z([qubits[0], qubits[1]], qubits[2]);
    X(qubits[0]); X(qubits[1]); X(qubits[2]);
    H(qubits[0]); H(qubits[1]); H(qubits[2]);
}

State Vector and Wave-Function Evolution

sequenceDiagram
    autonumber
    actor Driver as Main.qs (@EntryPoint)
    participant Q as Qubit Register |000⟩
    participant H as Superposition (H ⊗ n)
    participant Ora as Oracle (Phase Kickback)
    participant Dif as Diffusion (2|s⟩⟨s| - I)
    participant Meas as Measurement & ResetAll

    Driver->>Q: Allocate 3 Qubits via use block (|000⟩)
    Q->>H: Apply H ⊗ H ⊗ H (8 equal amplitudes = 1/√8)
    loop Optimal Iterations (R = 2 for N=8)
        H->>Ora: Invert phase of secret PIN |101⟩ (alpha -> -alpha)
        Ora->>Dif: Invert amplitudes about mean (Constructive interference)
    end
    Dif->>Meas: Collapse wave function (Target amplitude ~0.97, P ~94.5%)
    Meas->>Driver: Return Cracked PIN: '101'
    Driver->>Q: Explicit ResetAll(qs) memory release
Loading

The probability amplitude $\alpha_i$ evolves through four distinct stages:

State Vector Evolution

  1. Initial Uniform Superposition: Equal distribution ($\alpha_i = 1/\sqrt{8} \approx 0.3536, P = 12.5%$).
  2. Oracle Phase Inversion: Sign inversion of target PIN $|101\rangle$ ($\alpha_{101} \to -0.3536$).
  3. Diffusion Iteration 1: Constructive boost to $\alpha_{101} \approx 0.8840$ ($P \approx 78.1%$).
  4. Diffusion Iteration 2 (Optimal): Final amplification to $\alpha_{101} \approx 0.9724$ ($P \approx 94.53%$).

The Overcooking Phenomenon and Hilbert Space Geometry

In quantum computing, more iterations do not equal higher accuracy. Grover search operates as a geometric rotation in a 2D Hilbert subspace spanned by the uniform superposition $|s\rangle$ and the target state $|\omega\rangle$.

Overcooking Curve

Hilbert Space Rotation

Monte Carlo Sweep Data (Target PIN: 101, 500 Trials per Step)

Iteration Count ($k$) Regime Description State Angle ($(2k+1)\theta$) Theoretical Success Rate Empirical Success Rate Measured Count
$k = 1$ Under-rotated $62.1^\circ$ $78.12%$ $77.8%$ 389 / 500
$k = 2$ Optimal Peak $103.5^\circ$ $94.53%$ $97.0%$ 485 / 500
$k = 3$ Over-rotated $144.9^\circ$ $33.20%$ $31.2%$ 156 / 500
$k = 4$ Severely Decayed $186.3^\circ$ $1.20%$ $1.4%$ 7 / 500

$$\theta = \arcsin\left(\frac{1}{\sqrt{8}}\right) \approx 20.70^\circ, \quad P(k) = \sin^2((2k+1)\theta)$$


Quantitative Benchmark Matrix

Quantum vs Classical Comparison

Summary Comparison Table

Scale Register Search Space ($N$) Classical Queries (Avg) Quantum Queries ($R$) Success Rate Speedup Advantage
Phase 1 Baseline 2 Qubits 4 states (00-11) 2.50 queries 1 query 100.0% $2.50\times$ Speedup
Phase 2 Scaling 3 Qubits 8 states (000-111) 4.50 queries 2 queries 95.1% $2.25\times$ Speedup

For complete numerical tables across all 8 individual PIN states, see docs/results.md.


Asymptotic Scaling and Cryptanalytic Implications

As key sizes scale from $N=4$ (2 bits) to $N=256$ (8 bits), the quadratic divergence between classical brute-force $\mathcal{O}(N)$ and Grover's search $\mathcal{O}(\sqrt{N})$ demonstrates why quantum computing impacts symmetric cryptographic key sizes:

Asymptotic Scaling Curve

  • At $N=256$, classical search requires $\approx 128$ queries on average.
  • Grover search requires only $\approx 12$ queries, demonstrating a $10.7\times$ speedup factor.

Interactive Terminal Demonstration Modes

The project includes a standalone CLI demonstration engine (scripts/interactive_cracker.py) with zero-flicker 60FPS ANSI rendering:

# Mode 1: Direct quantum state vector evolution for PIN '101'
python scripts/interactive_cracker.py 101

# Mode 2: Live side-by-side race (Classical Brute-Force vs Quantum Grover)
python scripts/interactive_cracker.py --race 101

# Mode 3: Live Overcooking demonstration (k=1 to k=4 decay)
python scripts/interactive_cracker.py --overcook

Azure Quantum Cloud Integration

The circuit is fully compatible with cloud QPU backends via Azure Quantum:

from azure.quantum import Workspace

workspace = Workspace(
    resource_id="<YOUR_AZURE_QUANTUM_RESOURCE_ID>",
    location="eastus"
)

# Connect to cloud simulators or QPUs (e.g., IonQ, Rigetti, Quantinuum)
target = workspace.get_targets("ionq.simulator")
print(f"Target Availability: {target.current_availability}")

Engineering Decisions and Q# Best Practices

1. Safe Qubit Lifecycle Management with ResetAll

QDK throws strict runtime exceptions if released qubits remain entangled or in non-zero states. Every execution path enforces ResetAll(qs) immediately after measurement before exiting the use block.

2. Modularity and Educational Inline Commenting

In accordance with qsharp-code-style, the main entry point is separated from core unitary gates, and every gate is commented with the mathematical/physical "Why" (e.g., phase kickback, basis change).

3. Arbitrary PIN Support via Dynamic Basis Inversion

Rather than hardcoding |111⟩, pre/post-conditioning $X$ gates temporarily flip zero-bits to one-bits, allowing a single Controlled Z gate to mark any arbitrary PIN dynamically.


What I Learned and Internship Insights

Throughout this Microsoft Quantum onboarding project:

  • Quantum State Geometry: Grasped that amplitude amplification is a continuous rotation in Hilbert space, demystifying why over-rotating leads to catastrophic fidelity loss.
  • Q# & QIR Toolchain: Mastered writing, compiling, and testing native Q# algorithms using modern QDK and Python bindings.
  • Resource Discipline: Learned the critical importance of uncomputing ancillary states and explicitly resetting quantum registers.

Quickstart and Installation

Prerequisites

  • Operating System: Windows 10/11, macOS, or Linux
  • Python: 3.10, 3.11, or 3.12
  • Hardware: Standard CPU (runs locally on Microsoft Quantum QDK Simulator)

1. Clone & Set Up Environment

git clone https://github.com/rbvwolf/ms-quantum-pin-cracker.git
cd ms-quantum-pin-cracker

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

2. Run the Benchmark Suite

python scripts/run_benchmark.py

3. Regenerate Visual Charts

python scripts/generate_charts.py

License and Author Acknowledgments

This project is licensed under the MIT License. See the LICENSE file for complete details.


Developed by Yiğit Mert YILMAZ
Microsoft AI Innovators Summer Internship Program (Quantum Programming Onboarding Track)
LinkedIn Profile · GitHub Profile

About

Microsoft Quantum Onboarding Project: Scalable 2/3-Qubit PIN Cracker & Overcooking Analysis (Grover's Algorithm) with Azure Quantum QDK

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages