{"id":20824910,"url":"https://github.com/hornc/quantum-isbn-validator","last_synced_at":"2026-04-24T06:31:35.459Z","repository":{"id":43759368,"uuid":"459466951","full_name":"hornc/quantum-isbn-validator","owner":"hornc","description":"A quantum algorithm .... to validate ISBNs","archived":false,"fork":false,"pushed_at":"2022-02-19T07:40:29.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T14:32:29.573Z","etag":null,"topics":["isbn","quantum-algorithms","quantum-computing","validation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hornc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-15T07:10:05.000Z","updated_at":"2022-05-16T20:10:38.000Z","dependencies_parsed_at":"2022-07-21T01:18:33.635Z","dependency_job_id":null,"html_url":"https://github.com/hornc/quantum-isbn-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hornc/quantum-isbn-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hornc%2Fquantum-isbn-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hornc%2Fquantum-isbn-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hornc%2Fquantum-isbn-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hornc%2Fquantum-isbn-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hornc","download_url":"https://codeload.github.com/hornc/quantum-isbn-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hornc%2Fquantum-isbn-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32212805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["isbn","quantum-algorithms","quantum-computing","validation"],"created_at":"2024-11-17T22:24:14.466Z","updated_at":"2026-04-24T06:31:35.444Z","avatar_url":"https://github.com/hornc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quantum ISBN validator\n\n![tests](https://github.com/hornc/quantum-isbn-validator/actions/workflows/tests.yml/badge.svg)\n\nCopyright © 2022 Charles Horn.\n\nImplements a quantum algorithm to validate ISBN check digits using a single qubit.\n\nIt accepts 10 digit and 13 digit ISBNs. 10 digit ISBNs use a different checkdigit validation scheme. In this algorithm that corresponds to a slightly different phase encoding of each digit on the single qubit. \n\nBecause ISBN-13s are EAN-13s (aka GTIN-13), it will also validate checkdigits of those 13 digit product codes, commonly found on various products as barcodes.\n\n## Goal\nApply practical quantum computing to the problem of ISBN validation; primarily for education and illustrative purposes.\n\n## Algorithm description\n\nISBN checkdigits are determined via a weighted sum modulo _n_ operation. Validating the checkdigit is achieved by performing a similar weighted sum of all digits, including the checkdigit, and confirming the modulo _n_ result is 0.\n\n### Quantum implementation\n\nFirst we put our single qubit into a superposition state by setting it to **|1\u003e**, then applying the Hadamard operation.\n\nEncoding each weighted digit as multiples of a qubit phase rotation of _θ_ (dependant on the particular modulus) on a single qubit allows the sum to be built up.\n\n* For ISBN-13; _θ_ = 2π/10 radians\n* For ISBN-10; _θ_ = 2π/11 radians\n\nThe weighting is a function of the digit position. In the ISBN-13 scheme, odd positions have a x3 weighting. In the ISBN-10 scheme each digit is weighted by its position (leftmost digit is 10).\nIn this quantum implementation, this is the required encoding step to get our classical data into our quantum system.\n\nTo verify the check digit, we apply another Hadamard operation and then read the qubit. Only a correct checkdigit will provide 100% probability of reading a **1**.\n\nFor consistency in the qubit results, the code encodes input values with neither 10 nor 13 digits as a single phase rotation of 180 degrees to ensure 100% probability of reading a **0**, which can indicate the input was not recognised as an ISBN at all. (Otherwise a PHASE rotation of 0 looks like a validation). Some correct length ISBN-like values can produce this guaranteed **0** too, but they will have invalid checkdigits.\n\n`matplotlib` output for a ISBN-13 validation circuit:\n![Quantum circuit for ISBN-13 validation](img/ISBN13-circuit.png)\n\n## Usage examples\nRequires Python, [Qiskit](https://qiskit.org/), and `matplotlib` (for displaying the quantum circuits).\n\n\nPositive validation:\n```\n$ ./qisbn.py 9781492039686\nValidating ISBN 9781492039686...\nShots: 300\nCounts: {'1': 300}\nISBN 9781492039686 validates!\n```\nNegative result:\n```\n$ ./qisbn.py 9781492039684\nValidating ISBN 9781492039684...\nShots: 300\nCounts: {'0': 98, '1': 202}\n9781492039684 does not validate!\n```\n\n## Original circuit\nBelow is the original version of my validation algorithm attempt, which uses 3 qubits and a swap check to determine whether the weighted sum modulo _n_ is equal to the phase encoded checkdigit (negative rotation).\nThe circuit is a bit more interesting and gives the same result, but after creating it and seeing how it worked, I realised it was uneccesarily complex and could be simplified to use\nonly one qubit for the same functionality.\n\nHere is that earlier circuit drawn using [QCEngine](https://oreilly-qc.github.io/docs/build/index.html):\n\n![Earlier 3 qubit version of an ISBN validation circuit](img/original-qISBN-circuit.png)\n\n\n## License\nThis project is licensed under the terms of the [MIT license](LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhornc%2Fquantum-isbn-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhornc%2Fquantum-isbn-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhornc%2Fquantum-isbn-validator/lists"}