{"id":19603038,"url":"https://github.com/jemtaly/pypbc","last_synced_at":"2025-07-23T12:03:25.062Z","repository":{"id":224497286,"uuid":"763412181","full_name":"Jemtaly/pypbc","owner":"Jemtaly","description":"Python wrapper for the PBC (Pairing-Based Cryptography) library","archived":false,"fork":false,"pushed_at":"2024-03-10T19:26:02.000Z","size":132,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-23T13:46:33.921Z","etag":null,"topics":["bilinear-pairing","cryptography","python-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"debatem1/pypbc","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jemtaly.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-02-26T08:45:56.000Z","updated_at":"2025-02-20T03:28:36.000Z","dependencies_parsed_at":"2024-03-10T20:32:14.132Z","dependency_job_id":null,"html_url":"https://github.com/Jemtaly/pypbc","commit_stats":null,"previous_names":["jemtaly/pypbc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Jemtaly/pypbc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jemtaly%2Fpypbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jemtaly%2Fpypbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jemtaly%2Fpypbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jemtaly%2Fpypbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jemtaly","download_url":"https://codeload.github.com/Jemtaly/pypbc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jemtaly%2Fpypbc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266673524,"owners_count":23966372,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bilinear-pairing","cryptography","python-library"],"created_at":"2024-11-11T09:27:41.467Z","updated_at":"2025-07-23T12:03:24.942Z","avatar_url":"https://github.com/Jemtaly.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyPBC\n\nPyPBC is a Python wrapper for the PBC (Pairing-Based Cryptography) library, allowing for easy use of pairing-based cryptography in Python.\n\n***Note: Since the PBC library hasn't been maintained for a long time, there are some security issues, and the performance is lower than the current alternatives. Therefore, unless you have special requirements, it is not recommended to use this library. You can consider switching to [pymcl](https://github.com/Jemtaly/pymcl), which is a Python wrapper for the faster and securer [mcl](https://github.com/herumi/mcl) library, and supports the Windows platform. It currently provides support for the BLS12-381 curve only.***\n\n## Installation\n\nFor Debian-based systems, you can simply install the package using the provided `install.sh` script.\n\nFor other systems, please refer to the instructions [here](INSTALL).\n\n## Basic Usage\n\nThe library provides a simple interface to the PBC library, allowing for easy use of pairing-based cryptography in Python. Here is are some examples of how to use the library.\n\n```python\nfrom pypbc import *\n\n# Initialize a set of parameters from a string \n# check the PBC documentation (http://crypto.stanford.edu/pbc/manual/) for more information\nparams = Parameters(\n    \"type a\\n\"\n    \"q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791\\n\"\n    \"h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776\\n\"\n    \"r 730750818665451621361119245571504901405976559617\\n\"\n    \"exp2 159\\n\"\n    \"exp1 107\\n\"\n    \"sign1 1\\n\"\n    \"sign0 1\\n\"\n)\n\n# Initialize the pairing\npairing = Pairing(params)\n\n# show the order of the pairing\nprint(pairing.order())\n\n# Generate random elements\ng1 = Element.random(pairing, G1)\ng2 = Element.random(pairing, G2)\nz1 = Element.random(pairing, Zr)\nz2 = Element.random(pairing, Zr)\n\n# Check the properties of the pairing\nassert pairing.apply(g1 ** z1, g2 ** z2) == pairing.apply(g1, g2) ** (z1 * z2)\n```\n\n## Method list\n\nThe following methods are available in the `pypbc` module:\n\n### `Parameters`\n\n- `__init__(self, string: str) -\u003e None`: Initialize the parameters from a string.\n- `__str__(self) -\u003e str`: Return the string representation of the parameters.\n\n### `Pairing`\n    \n- `__init__(self, params: Parameters) -\u003e None`: Initialize the pairing from the given parameters.\n- `order(self) -\u003e int`: Return the order of the pairing (Zr, G1, G2 and GT).\n- `apply(self, e1: Element, e2: Element) -\u003e Element`: Apply the pairing to the given elements.\n- `is_symmetric(self) -\u003e bool`: Return whether the pairing is symmetric.\n\n### `Element`\n    \n#### Constructors\n\n- `__init__(self, pairing: Pairing, type: int, string: str) -\u003e None`: Initialize the element from a string.\n- `from_int(pairing: Pairing, value: int) -\u003e Element`: Return an element in Zr from the given integer.\n- `random(pairing: Pairing, type: int) -\u003e Element`: Return a random element of the given type.\n- `zero(pairing: Pairing, type: int) -\u003e Element`: Return the additive identity element of the given type.\n- `one(pairing: Pairing, type: int) -\u003e Element`: Return the multiplicative identity element of the given type.\n- `from_hash(pairing: Pairing, type: int, data: bytes) -\u003e Element`: Return an element from the given hash.\n\n#### Serialize and Deserialize\n\n- `to_bytes(self) -\u003e bytes`: Return the byte representation of the element.\n- `to_bytes_compressed(self) -\u003e bytes`: Return the compressed byte representation of the element. (Only for G1 and G2 elements)\n- `to_bytes_x_only(self) -\u003e bytes`: Return the x-only byte representation of the element. (Only for G1 and G2 elements)\n- `from_bytes(pairing: Pairing, type: int, data: bytes) -\u003e Element`: Return an element from the given byte representation.\n- `from_bytes_compressed(pairing: Pairing, type: int, data: bytes) -\u003e Element`: Return an element from the given compressed byte representation. (Only for G1 and G2 elements)\n- `from_bytes_x_only(pairing: Pairing, type: int, data: bytes) -\u003e Element`: Return an element from the given x-only byte representation. (Only for G1 and G2 elements)\n\n#### Properties\n\n- `order(self)`: Return the order of the element.\n- `__getitem__(self, index: int) -\u003e Element`: Return the i-th item of the element (if it is multidimensional).\n- `__len__(self) -\u003e int`: Return the length of the element, returns 0 if the element is one-dimensional.\n\n#### Typecasting\n\n- `__str__(self) -\u003e str`: Return the string representation of the element.\n- `__int__(self) -\u003e int`: Return the integer representation of the element (if possible).\n\n#### Hashable\n\n- `__hash__(self) -\u003e int`: Return the hash value of the element.\n\n#### Arithmetic Operations\n\n- `__add__(self, other: Element) -\u003e Element`: Return the sum of the elements.\n- `__sub__(self, other: Element) -\u003e Element`: Return the difference of the elements.\n- `__mul__(self, other: Element | int) -\u003e Element`: Return the product of the elements, same as `__add__` method if the two operands are both in G1, G2 or GT, and same as `__pow__` if one of the operands is an integer or an element of Zr and another is in G1, G2 or GT.\n- `__truediv__(self, other: Element) -\u003e Element`: Return the quotient of the elements, the two operands must be in same field, it is same as `__sub__` if the two operands are both in G1, G2 or GT. ***Notice: Division between elements in G1,G2 or GT and elements in Zr is not allowed because this is not supported by the original pbc library. If you want to perform this operation, you can multiply the inverse of the Zr element (`g * ~x`) instead.***\n- `__pow__(self, other: Element | int) -\u003e Element`: Return the power of the element, the exponent can be an integer or an element of Zr.\n- `__neg__(self) -\u003e Element`: Return the additive inverse of the element.\n- `__invert__(self) -\u003e Element`: Return the multiplicative inverse of the element, same as `__neg__` if the element is in G1, G2 or GT.\n\n#### Comparison Operations\n\n- `__eq__(self, other: Element) -\u003e bool`: Return whether the elements are equal.\n- `__ne__(self, other: Element) -\u003e bool`: Return whether the elements are not equal.\n- `is0(self) -\u003e bool`: Return whether the element is the additive identity.\n- `is1(self) -\u003e bool`: Return whether the element is the multiplicative identity.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjemtaly%2Fpypbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjemtaly%2Fpypbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjemtaly%2Fpypbc/lists"}