{"id":15890351,"url":"https://github.com/mhostetter/galois","last_synced_at":"2026-01-02T05:38:12.755Z","repository":{"id":38379422,"uuid":"312901841","full_name":"mhostetter/galois","owner":"mhostetter","description":"A performant NumPy extension for Galois fields and their applications","archived":false,"fork":false,"pushed_at":"2025-04-12T16:47:23.000Z","size":136983,"stargazers_count":387,"open_issues_count":43,"forks_count":33,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-12T19:05:22.714Z","etag":null,"topics":["aes","bch","coding-theory","cryptography","elliptic-curve-cryptography","elliptic-curves","encryption","error-control-coding","finite-fields","galois","galois-fields","lfsr","ntt","number-theory","numpy","python","reed-solomon","rsa"],"latest_commit_sha":null,"homepage":"https://mhostetter.github.io/galois/","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/mhostetter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-11-14T21:05:20.000Z","updated_at":"2025-04-09T19:21:54.000Z","dependencies_parsed_at":"2023-02-15T03:16:07.692Z","dependency_job_id":"26435dab-ba1f-4d63-85e7-efee4b34dcf0","html_url":"https://github.com/mhostetter/galois","commit_stats":{"total_commits":1383,"total_committers":13,"mean_commits":"106.38461538461539","dds":0.04266088214027475,"last_synced_commit":"c945356533b369adc4860e7979c34b04c862ba1d"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhostetter%2Fgalois","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhostetter%2Fgalois/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhostetter%2Fgalois/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhostetter%2Fgalois/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhostetter","download_url":"https://codeload.github.com/mhostetter/galois/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968914,"owners_count":21191162,"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":["aes","bch","coding-theory","cryptography","elliptic-curve-cryptography","elliptic-curves","encryption","error-control-coding","finite-fields","galois","galois-fields","lfsr","ntt","number-theory","numpy","python","reed-solomon","rsa"],"created_at":"2024-10-06T07:05:19.599Z","updated_at":"2026-01-02T05:38:12.750Z","avatar_url":"https://github.com/mhostetter.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# ![Galois: A performant NumPy extension for Galois fields and their applications](https://raw.githubusercontent.com/mhostetter/galois/main/logo/galois-heading.png)\n\n\u003cdiv align=center\u003e\n  \u003ca href=\"https://pypi.org/project/galois\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/galois\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/galois\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/galois\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/galois\"\u003e\u003cimg src=\"https://img.shields.io/pypi/wheel/galois\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=center\u003e\n  \u003ca href=\"https://pypistats.org/packages/galois\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/galois\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/galois\"\u003e\u003cimg src=\"https://img.shields.io/pypi/l/galois\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/galois_py\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=follow\u0026message=@galois_py\u0026color=blue\u0026logo=twitter\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=center\u003e\n  \u003ca href=\"https://github.com/mhostetter/galois/actions/workflows/lint.yaml\"\u003e\u003cimg src=\"https://github.com/mhostetter/galois/actions/workflows/lint.yaml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/mhostetter/galois/actions/workflows/build.yaml\"\u003e\u003cimg src=\"https://github.com/mhostetter/galois/actions/workflows/build.yaml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/mhostetter/galois/actions/workflows/test.yaml\"\u003e\u003cimg src=\"https://github.com/mhostetter/galois/actions/workflows/test.yaml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/mhostetter/galois\"\u003e\u003cimg src=\"https://codecov.io/gh/mhostetter/galois/branch/main/graph/badge.svg?token=3FJML79ZUK\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\nThe `galois` library is a Python 3 package that extends NumPy arrays to operate over finite fields.\n\n\u003e Enjoying the library? Give us a :star: on [GitHub](https://github.com/mhostetter/galois)!\n\nThe user creates a [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) subclass using `GF = galois.GF(p**m)`.\n`GF` is a subclass of `np.ndarray` and its constructor `x = GF(array_like)` mimics the signature of `np.array()`. The\n[`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) `x` is operated on like any other NumPy array except\nall arithmetic is performed in $\\mathrm{GF}(p^m)$, not $\\mathbb{R}$.\n\nInternally, the finite field arithmetic is implemented by replacing [NumPy ufuncs](https://numpy.org/doc/stable/reference/ufuncs.html) with specialized versions.\nThe new ufuncs are written in pure Python and [just-in-time compiled](https://numba.pydata.org/numba-doc/dev/user/vectorize.html) with\n[Numba](https://numba.pydata.org/). The ufuncs can be configured to use either lookup tables (for speed) or explicit calculation (for memory savings).\n\n\u003e **Warning**\n\u003e The algorithms implemented in the NumPy ufuncs are not constant-time, but were instead designed for performance. As such, the library could be vulnerable to a [side-channel timing attack](https://en.wikipedia.org/wiki/Timing_attack). This library is not intended for production security, but instead for research \u0026 development, reverse engineering, cryptanalysis, experimentation, and general education.\n\n## Features\n\n- Supports all [Galois fields](https://mhostetter.github.io/galois/latest/api/galois.GF/) $\\mathrm{GF}(p^m)$, including arbitrarily large fields.\n- [**Faster**](https://mhostetter.github.io/galois/latest/performance/prime-fields/) than native NumPy. `GF(x) * GF(y)` is often faster than `(x * y) % p` for $\\mathrm{GF}(p)$.\n- Seamless integration with NumPy -- normal NumPy functions work on [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/)s.\n- Linear algebra over finite fields using normal [`np.linalg`](https://mhostetter.github.io/galois/latest/basic-usage/array-arithmetic/#linear-algebra) functions.\n- Linear transforms over finite fields, such as the FFT with [`np.fft.fft()`](https://mhostetter.github.io/galois/latest/basic-usage/array-arithmetic/#advanced-arithmetic) and the NTT with [`ntt()`](https://mhostetter.github.io/galois/latest/api/galois.ntt/).\n- Functions to generate [irreducible](https://mhostetter.github.io/galois/latest/api/#irreducible-polynomials), [primitive](https://mhostetter.github.io/galois/latest/api/#primitive-polynomials), and [Conway](https://mhostetter.github.io/galois/latest/api/galois.conway_poly/) polynomials.\n- Univariate polynomials over finite fields with [`Poly`](https://mhostetter.github.io/galois/latest/api/galois.Poly/).\n- Forward error correction codes with [`BCH`](https://mhostetter.github.io/galois/latest/api/galois.BCH/) and [`ReedSolomon`](https://mhostetter.github.io/galois/latest/api/galois.ReedSolomon/).\n- Fibonacci and Galois linear-feedback shift registers over any finite field with [`FLFSR`](https://mhostetter.github.io/galois/latest/api/galois.FLFSR/) and [`GLFSR`](https://mhostetter.github.io/galois/latest/api/galois.GLFSR/).\n- Various [number theoretic functions](https://mhostetter.github.io/galois/latest/api/#number-theory).\n- [Integer factorization](https://mhostetter.github.io/galois/latest/api/#factorization) and accompanying algorithms.\n- [Prime number generation](https://mhostetter.github.io/galois/latest/api/#prime-number-generation) and [primality testing](https://mhostetter.github.io/galois/latest/api/#primality-tests).\n\n## Roadmap\n\n- Galois ring arrays\n- GPU support\n- Elliptic curves over finite fields\n\n## Documentation\n\nThe documentation for `galois` is located at https://mhostetter.github.io/galois/latest/.\n\n## Getting Started\n\nThe [Getting Started](https://mhostetter.github.io/galois/latest/getting-started/) guide is intended to assist users with installing the\nlibrary, creating two example arrays, and performing basic array arithmetic. See [Basic Usage](https://mhostetter.github.io/galois/latest/basic-usage/array-classes/)\nfor more detailed discussions and examples.\n\n### Install the package\n\nThe latest version of `galois` can be installed from [PyPI](https://pypi.org/project/galois/) using `pip`.\n\n```console\n$ python3 -m pip install galois\n```\n\nImport the `galois` package in Python.\n\n```python\nIn [1]: import galois\n\nIn [2]: galois.__version__\nOut[2]: '0.4.10'\n```\n\n### Create a [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) subclass\n\nNext, create a [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) subclass\nfor the specific finite field you'd like to work in. This is created using the `galois.GF()` class factory. In this example, we are\nworking in $\\mathrm{GF}(3^5)$.\n\n```python\nIn [3]: GF = galois.GF(3**5)\n\nIn [4]: print(GF.properties)\nGalois Field:\n  name: GF(3^5)\n  characteristic: 3\n  degree: 5\n  order: 243\n  irreducible_poly: x^5 + 2x + 1\n  is_primitive_poly: True\n  primitive_element: x\n```\n\nThe [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) subclass `GF` is a subclass of\n`np.ndarray` that performs all arithmetic in the Galois field $\\mathrm{GF}(3^5)$, rather than the real numbers\n$\\mathbb{R}$.\n\n```python\nIn [5]: issubclass(GF, galois.FieldArray)\nOut[5]: True\n\nIn [6]: issubclass(GF, np.ndarray)\nOut[6]: True\n```\n\nSee [Array Classes](https://mhostetter.github.io/galois/latest/basic-usage/array-classes/) for more details.\n\n### Create two [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) instances\n\nNext, create a new [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) `x` by passing an\n[`ArrayLike`](https://mhostetter.github.io/galois/latest/api/galois.typing.ArrayLike/) object to `GF`'s constructor.\n\n```python\nIn [7]: x = GF([236, 87, 38, 112]); x\nOut[7]: GF([236,  87,  38, 112], order=3^5)\n```\n\nThe array `x` is an instance of [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) and also\nan instance of `np.ndarray`.\n\n```python\nIn [8]: isinstance(x, galois.FieldArray)\nOut[8]: True\n\nIn [9]: isinstance(x, np.ndarray)\nOut[9]: True\n```\n\nCreate a second [`FieldArray`](https://mhostetter.github.io/galois/latest/api/galois.FieldArray/) `y` by converting an existing\nNumPy array (without copying it) by invoking `.view()`. When finished working in the finite field, view it back as a NumPy array\nwith `.view(np.ndarray)`.\n\n```python\n# y represents an array created elsewhere in the code\nIn [10]: y = np.array([109, 17, 108, 224]); y\nOut[10]: array([109,  17, 108, 224])\n\nIn [11]: y = y.view(GF); y\nOut[11]: GF([109,  17, 108, 224], order=3^5)\n```\n\nSee [Array Creation](https://mhostetter.github.io/galois/latest/basic-usage/array-creation/) for more details.\n\n### Change the element representation\n\nThe representation of finite field elements can be set to either the integer (`\"int\"`), polynomial (`\"poly\"`),\nor power (`\"power\"`) representation. The default representation is the integer representation since integers are natural when\nworking with integer NumPy arrays.\n\nSet the element representation by passing the `repr` keyword argument to `galois.GF()` or by calling the `repr()`\nclassmethod. Choose whichever element representation is most convenient.\n\n```python\n# The default is the integer representation\nIn [12]: x\nOut[12]: GF([236,  87,  38, 112], order=3^5)\n\nIn [13]: GF.repr(\"poly\"); x\nOut[13]:\nGF([2α^4 + 2α^3 + 2α^2 + 2,               α^4 + 2α,\n             α^3 + α^2 + 2,      α^4 + α^3 + α + 1], order=3^5)\n\nIn [14]: GF.repr(\"power\"); x\nOut[14]: GF([α^204,  α^16, α^230,  α^34], order=3^5)\n\n# Reset to the integer representation\nIn [15]: GF.repr(\"int\");\n```\n\nSee [Element Representation](https://mhostetter.github.io/galois/latest/basic-usage/element-representation/) for more details.\n\n### Perform array arithmetic\n\nOnce you have two Galois field arrays, nearly any arithmetic operation can be performed using normal NumPy arithmetic.\nThe traditional [NumPy broadcasting rules](https://numpy.org/doc/stable/user/basics.broadcasting.html) apply.\n\nStandard element-wise array arithmetic -- addition, subtraction, multiplication, and division -- are easily preformed.\n\n```python\nIn [16]: x + y\nOut[16]: GF([ 18,  95, 146,   0], order=3^5)\n\nIn [17]: x - y\nOut[17]: GF([127, 100, 173, 224], order=3^5)\n\nIn [18]: x * y\nOut[18]: GF([ 21, 241, 179,  82], order=3^5)\n\nIn [19]: x / y\nOut[19]: GF([ 67,  47, 192,   2], order=3^5)\n```\n\nMore complicated arithmetic, like square root and logarithm base $\\alpha$, are also supported.\n\n```python\nIn [20]: np.sqrt(x)\nOut[20]: GF([ 51, 135,  40,  16], order=3^5)\n\nIn [21]: np.log(x)\nOut[21]: array([204,  16, 230,  34])\n```\n\nSee [Array Arithmetic](https://mhostetter.github.io/galois/latest/basic-usage/array-arithmetic/) for more details.\n\n## Acknowledgements\n\nThe `galois` library is an extension of, and completely dependent on, [NumPy](https://numpy.org/). It also heavily\nrelies on [Numba](https://numba.pydata.org/) and the [LLVM just-in-time compiler](https://llvm.org/) for optimizing performance\nof the finite field arithmetic.\n\n[Frank Luebeck's compilation](http://www.math.rwth-aachen.de/~Frank.Luebeck/data/ConwayPol/index.html) of Conway polynomials and\n[Wolfram's compilation](https://datarepository.wolframcloud.com/resources/Primitive-Polynomials/) of primitive polynomials are used\nfor efficient polynomial lookup, when possible.\n\n[The Cunningham Book's tables](https://homes.cerias.purdue.edu/~ssw/cun/third/index.html) of prime factorizations, $b^n \\pm 1$\nfor $b \\in \\{2, 3, 5, 6, 7, 10, 11, 12\\}$, are used to generate factorization lookup tables. These lookup tables speed-up the\ncreation of large finite fields by avoiding the need to factor large integers.\n\n[Sage](https://www.sagemath.org/) is used extensively for generating test vectors for finite field arithmetic and polynomial arithmetic.\n[SymPy](https://www.sympy.org/en/index.html) is used to generate some test vectors. [Octave](https://www.gnu.org/software/octave/index)\nis used to generate test vectors for forward error correction codes.\n\nThis library would not be possible without all of the other libraries mentioned. Thank you to all their developers.\n\n## Citation\n\nIf this library was useful to you in your research, please cite us. Following the [GitHub citation standards](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files), here is the recommended citation.\n\n### BibTeX\n\n```bibtex\n@software{Hostetter_Galois_2020,\n    title = {{Galois: A performant NumPy extension for Galois fields}},\n    author = {Hostetter, Matt},\n    month = {11},\n    year = {2020},\n    url = {https://github.com/mhostetter/galois},\n}\n```\n\n### APA\n\n```\nHostetter, M. (2020). Galois: A performant NumPy extension for Galois fields [Computer software]. https://github.com/mhostetter/galois\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhostetter%2Fgalois","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhostetter%2Fgalois","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhostetter%2Fgalois/lists"}