Factor large numbers efficiently using quantum computing principles.
⚙️ Run DemoShor's algorithm leverages quantum superposition and entanglement to find the period of a function, which is used to factor large integers exponentially faster than classical algorithms.
import { QuantumCircuit, ShorFactorizer } from '@quantum-sig/core';
// Factor the number 15 using Shor's algorithm
async function runShor() {
const target = 15;
const circuit = QuantumCircuit.builder()
.addQubits(4) // Quantum register for period
.addQubits(4) // Quantum register for function
.applyHadamardToAll()
.measureLastRegister();
const factorizer = new ShorFactorizer(target);
const result = await factorizer.run(circuit);
console.log('Found factors:', result.factors);
document.getElementById('results').innerText =
`Factors of ${target} = ${result.factors.join(' * ')}`;
}
runShor();
This example demonstrates the core quantum steps for factoring integers, which has profound implications for cryptography.
Interactive visualization of qubit states during period-finding