zmodn

The Zmodn package provides a class for representing integers modulo a given prime number. This class can be used to applications such as cryptography and computer algebra.

https://github.com/asanchezyali/zmodn

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.8%) to scientific vocabulary

Keywords

arithmetic criptography galois-fields galois-group group-theory groups math mathematics mathematics-education mathematics-library modular-arithmetic number-theory
Last synced: 6 months ago · JSON representation ·

Repository

The Zmodn package provides a class for representing integers modulo a given prime number. This class can be used to applications such as cryptography and computer algebra.

Basic Info
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Topics
arithmetic criptography galois-fields galois-group group-theory groups math mathematics mathematics-education mathematics-library modular-arithmetic number-theory
Created over 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Zmodn: Practical Modular Arithmetic Using NumPy

Logo

Zmodn provides a Python class for representing and performing operations in the ring of integers modulo n (ℤ/nℤ). It's built on NumPy for efficient array operations, making it suitable for applications in cryptography, computer algebra, and other fields requiring modular arithmetic.

Features

  • Perform modular arithmetic operations (addition, subtraction, multiplication, division, exponentiation)
  • Compute modular inverses
  • Handle matrix operations in modular arithmetic, including multiplication and inversion
  • Compare elements in modular arithmetic
  • Seamless integration with NumPy functions

Installation

Install Zmodn using pip:

bash pip install -e .

Quick Start

Here's a basic example of using the Zmodn class:

```python from zmodn import Zmodn

Create Zmodn objects

a = Zmodn([1, 2, 7], 5) b = Zmodn([3, 4, 2], 5)

print(a) # Output: 1 2 2 print(a + b) # Output: 4 1 4 print(a * b) # Output: 3 3 4 print(a.mod_inv()) # Output: 1 3 3 ```

Detailed Usage

Creating Zmodn Objects

```python

Single element

x = Zmodn(3, 7) # 3 (mod 7)

List of elements

y = Zmodn([1, 2, 3], 5) # 1 2 3

Matrix

z = Zmodn([[1, 2], [3, 4]], 6) # [1 2] [3 4] ```

Arithmetic Operations

```python a = Zmodn([1, 2], 7) b = Zmodn([3, 4], 7)

print(a + b) # Addition: 4 6 print(a - b) # Subtraction: 5 5 print(a * b) # Multiplication: 3 1 print(a / b) # Division: 5 4 print(a ** 2) # Exponentiation: 1 4 print(-a) # Negation: 6 5 ```

Matrix Operations

```python m1 = Zmodn([[1, 2], [3, 4]], 5) m2 = Zmodn([[2, 3], [1, 4]], 5)

print(m1 @ m2) # Matrix multiplication: [4 1] [0 0] print(m1.inv()) # Matrix inversion: [4 3] [2 4] ```

Modular Inverse

python x = Zmodn([2, 3], 5) print(x.mod_inv()) # Modular inverse: [3 2] (mod 5)

Comparison Operations

```python a = Zmodn([1, 2], 7) b = Zmodn([1, 3], 7)

print(a == b) # False print(a < b) # True print(a >= b) # False ```

Notes and Limitations

  • The mod_inv() method works for individual elements and vectors, but not for matrices. Use inv() for matrix inversion.
  • All operations assume that Zmodn objects have the same modulus.
  • The class includes type checking and error handling for invalid inputs.

Documentation

For more detailed information, please refer to the full documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Creative Commons Zero v1.0 Universal license. See the LICENSE file for details.

Citation

If you use Zmodn in your research, please cite it as follows:

bibtex @software{Sanchez_Alejandro_2020, title = {{Zmodn}: Practical Modular Arithmetic Using NumPy}, author = {Sánchez, Alejandro}, month = {11}, year = {2023}, url = {https://github.com/asanchezyali/Zmodn}, }

Contact

For questions or issues, please open an issue on GitHub or contact the maintainer directly. You can also join our Discord community for discussions, support, and updates: Math & Code Discord Server Join us to connect with other users, get help, and stay updated on the latest developments!

Owner

  • Name: Alejandro Sánchez Yalí
  • Login: asanchezyali
  • Kind: user
  • Company: Monadical

Mathematician with experience in Software Development, Data Science and Blockchain

Citation (CITATION.cff)

cff-version: 0.1.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Sánchez Yalí"
  given-names: "Alejandro"
title: "Practical Modular Arithmetic Using NumPy"
date-released: 2020-11-15
url: "https://github.com/asanchezyali/zmodn"

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Dependencies

.github/workflows/docs.yaml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • peaceiris/actions-gh-pages v3 composite
  • snok/install-poetry v1 composite
poetry.lock pypi
  • alabaster 0.7.16
  • annotated-types 0.7.0
  • appdirs 1.4.4
  • asttokens 2.4.1
  • babel 2.14.0
  • certifi 2024.2.2
  • cfgv 3.4.0
  • charset-normalizer 3.3.2
  • clang 17.0.6
  • colorama 0.4.6
  • decorator 5.1.1
  • distlib 0.3.7
  • docutils 0.20.1
  • executing 2.0.1
  • filelock 3.12.4
  • identify 2.5.30
  • idna 3.6
  • imagesize 1.4.1
  • iniconfig 2.0.0
  • ipython 8.26.0
  • jedi 0.19.1
  • jinja2 3.1.3
  • markdown 3.5.2
  • markdown-it-py 3.0.0
  • markupsafe 2.1.5
  • matplotlib-inline 0.1.7
  • mdit-py-plugins 0.4.1
  • mdurl 0.1.2
  • myst-parser 3.0.1
  • nodeenv 1.8.0
  • numpy 1.26.1
  • packaging 23.2
  • parso 0.8.4
  • pexpect 4.9.0
  • platformdirs 3.11.0
  • pluggy 1.3.0
  • pre-commit 3.5.0
  • prompt-toolkit 3.0.47
  • ptyprocess 0.7.0
  • pure-eval 0.2.3
  • pydantic 2.8.2
  • pydantic-core 2.20.1
  • pydantic-extra-types 2.9.0
  • pygments 2.17.2
  • pymdown-extensions 10.7
  • pytest 8.0.2
  • pyyaml 6.0.1
  • requests 2.31.0
  • setuptools 68.2.2
  • six 1.16.0
  • snowballstemmer 2.2.0
  • sphinx 7.4.7
  • sphinx-design 0.6.0
  • sphinx-immaterial 0.12.1
  • sphinx-jinja 2.0.2
  • sphinx-last-updated-by-git 0.3.7
  • sphinx-math-dollar 1.2.1
  • sphinxcontrib-applehelp 1.0.8
  • sphinxcontrib-devhelp 1.0.6
  • sphinxcontrib-htmlhelp 2.0.5
  • sphinxcontrib-jsmath 1.0.1
  • sphinxcontrib-qthelp 1.0.7
  • sphinxcontrib-serializinghtml 1.1.10
  • stack-data 0.6.3
  • traitlets 5.14.3
  • typing-extensions 4.12.2
  • urllib3 2.2.1
  • virtualenv 20.24.5
  • wcwidth 0.2.13
pyproject.toml pypi
  • clang ^17.0.6 develop
  • pre-commit ^3.5.0 develop
  • pymdown-extensions ^10.7 develop
  • pytest ^8.0.2 develop
  • sphinx-jinja ^2.0.2 develop
  • ipython ^8.26.0
  • myst-parser ^3.0.1
  • numpy ^1.26.1
  • python ^3.11
  • sphinx ^7.4.7
  • sphinx-design ^0.6.0
  • sphinx-immaterial ^0.12.1
  • sphinx-last-updated-by-git ^0.3.7
  • sphinx-math-dollar ^1.2.1