Skip to main content
Build Status Documentation Status

Description

Modular arithmetic is arithmetic for integers, where numbers wrap around when reaching a given value called modulus. For example 6 ≡ 1 (mod 5). Modular arithmetic has several practical applications including: music, banking, book publishing, cryptography… and of course math.

The purpose of this package is to simplify the use of modular arithmetic in Python3.

Usage

This package provides Mod integers that compute arithmetic operations like + - * // ** with a modulus:

from mod import Mod

# Funny math here

x = Mod(5, 7)      # x ≡ 5 (mod 7)

(x + 2) == 0       # True: 5 + 2 ≡ 7 ≡ 0 (mod 7)
(x + 7) == x       # True: 5 + 7 ≡ 12 ≡ 5 (mod 7)
(x**3) == (x + 1)  # True: 5³ ≡ 125 ≡ 6 (mod 7)
(1 // x) == 3      # True: 5 × 3 ≡ 15 ≡ 1 (mod 7) ⇒ 5⁻¹ ≡ 3 (mod 7)

A naive implementation of RSA encryption algorithm using mod package:

from mod import Mod


# My RSA keys
public_key = Mod(3, 61423)
private_key = Mod(40619, 61423)

# My very secret message
top_secret_message = 666

# RSA encryption
encrypted = top_secret_message**public_key

# RSA decryption
decrypted = encrypted**private_key

# My secret message have been correctly encrypted and decrypted :-)
assert decrypted == top_secret_message

Package documentation: mod.Mod

Install

Run the following command to install mod package

pip3 install mod

Indices

mod — Copyright (c) 2020 Y. SOMDA, MIT License

Metadata

Release files for mod 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mod 0.3.0
File Size Uploaded
mod-0.3.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mod 0.3.0
File Interpreter ABI Platform
mod-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / mod-0.3.0.tar.gz

Download URL mod-0.3.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b3462cb997ba4cb393fe91ebc8b94e574d93ae59ef6df8b13fdd44192b242842
BLAKE2b-256 checksum
How to use checksums
f172ef6f03a29c7b5da29fe05856716985efb51b3095e3ea31433638e3e3f64f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

Release files / mod-0.3.0-py3-none-any.whl

Download URL mod-0.3.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0416727a7172d426860185cfbf416268eb9dd1b44677eda000c0703304b23e2
BLAKE2b-256 checksum
How to use checksums
aca4bcd7f8c9bd1c4bc1c6ea7d1aa39cea0b38d8303f6f06994cac5264ecae22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.4

2 release files

0.2.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page