{"id":28456612,"url":"https://github.com/maple3142/gf2bv","last_synced_at":"2025-06-29T10:32:30.649Z","repository":{"id":258473501,"uuid":"873992503","full_name":"maple3142/gf2bv","owner":"maple3142","description":"Solving linear systems over GF(2) by manipulating bitvectors","archived":false,"fork":false,"pushed_at":"2025-04-05T08:06:25.000Z","size":136,"stargazers_count":42,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T23:08:18.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maple3142.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-17T04:28:24.000Z","updated_at":"2025-06-03T03:03:45.000Z","dependencies_parsed_at":"2025-04-05T09:29:07.044Z","dependency_job_id":null,"html_url":"https://github.com/maple3142/gf2bv","commit_stats":null,"previous_names":["maple3142/gf2bv"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maple3142/gf2bv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fgf2bv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fgf2bv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fgf2bv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fgf2bv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maple3142","download_url":"https://codeload.github.com/maple3142/gf2bv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fgf2bv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262578290,"owners_count":23331595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-06-06T23:08:21.304Z","updated_at":"2025-06-29T10:32:30.640Z","avatar_url":"https://github.com/maple3142.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gf2bv - Solving linear systems over GF(2) by manipulating bitvectors\n\n`gf2bv` allows you to build and solve linear systems over GF(2) by manipulating bitvectors, based on [M4RI](https://github.com/malb/m4ri).\n\n## Installation\n\nFirst, you need to have `m4ri` installed on your system, try some package names like `mr4i`, `libm4ri-dev` or something else depending on [your system](https://repology.org/project/libm4ri/versions).\n\nClone the repository and install the package with pip:\n\n```bash\npip install .\n```\n\nRequires Python 3.11 or later.\n\nYou can also set the `GF2BV_BUILD_M4RI` environment variable to automatically build `m4ri` from source:\n\n```bash\nGF2BV_BUILD_M4RI=1 pip install .\n```\n\n## Usage\n\nDefine a linear system using `LinearSystem` and get the symbolic bitvectors with `gens()`, then use the them to build the equations you want to solve. Equations are represented as a list of symbolic bitvectors that evaluate to zero named `zeros` (You can choose other names if you want), then pass them to `solve_one` or `solve_all` to get the solutions.\n\n### Find all solutions to a simple linear system\n\n```python\nfrom gf2bv import LinearSystem\n\nlin = LinearSystem([1, 1, 1, 1])\na, b, c, d = lin.gens()\n\n\"\"\"\nThis is the system we want to solve:\na + b + c = 1\nb + d = 0\na + c = 1\n\"\"\"\n\nzeros = [a ^ b ^ c ^ 1, b ^ d, a ^ c ^ 1]\nfor sol in lin.solve_all(zeros):\n    print(sol)\n```\n\n### Break a linear hash function\n\n```python\nfrom gf2bv import LinearSystem\nimport secrets\n\nMASK64 = (1 \u003c\u003c 64) - 1\n\n\ndef just_some_hash(x, y):\n    z1 = x ^ (y \u003e\u003e 22)\n    z2 = y ^ (x \u003c\u003c 13) \u0026 MASK64\n    z1 ^= (z2 \u003e\u003e 5) \u0026 0xDEADBEEFDEADBEEF\n    z2 ^= (z1 \u003c\u003c 7) | 0x1337314213373142\n    return z1, z2\n\n\nx, y = secrets.randbits(64), secrets.randbits(64)\nz1, z2 = just_some_hash(x, y)\n\nlin = LinearSystem([64, 64])\nxx, yy = lin.gens()\nzz1, zz2 = just_some_hash(xx, yy)\n\nzeros = [zz1 ^ z1, zz2 ^ z2]\nsol = lin.solve_one(zeros)\nassert sol == (x, y)\nassert just_some_hash(*sol) == (z1, z2)\nprint(sol)\n```\n\n### More examples\n\nCheck the [examples](examples) directory for more examples.\n\n## Prior work\n\nThis package is pretty similar to [xorsat](https://github.com/Lydxn/xorsat), but I keep most of the code in Python for flexibility and ease of use.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaple3142%2Fgf2bv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaple3142%2Fgf2bv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaple3142%2Fgf2bv/lists"}