MOMA: Moving Origin Modular Arithmetic
MOMA is a Rust framework for exploring number theory and cryptography through the lens of Moving Origin Modular Arithmetic.
The central idea is that the "zero point" or "origin" for modular arithmetic is not fixed. Instead, it shifts dynamically based on a contextual value—typically a prime number p. This provides a novel relational framework for analyzing the properties of integers.
The crate is designed for researchers and developers working in number theory, cryptography, and algorithmic data analysis.
Core Concepts
The MOMA framework is built on two simple but powerful concepts:
-
MomaRing: The primary object for all calculations. A ring is defined by amodulusand a chosenOriginStrategy. -
OriginStrategy: A trait that defines how the origin moves. This makes the framework highly extensible. You can define custom logic for the origin's movement based on any property of the contextual prime.
The core calculation is the MOMA residue, defined as:
$residue = (value + origin) \pmod{modulus}$
Built-in Strategies
The crate includes several pre-built strategies to get you started:
strategy::PrimeGap: The origin is the gap between a prime and its predecessor ($p - p_{prev}$).strategy::CompositeMass: The origin is the sum of prime factors of all composite numbers in the gap between a prime and its successor.strategy::Fixed: A simple strategy where the origin is a fixed constant.
Features
- Flexible Core: A powerful and extensible system based on the
MomaRingandOriginStrategytrait. - Analysis Tools: Includes high-level structs like
PrimeGapFieldfor statistical analysis of prime gaps. - Cryptographic Primitives: Demonstrates how MOMA can be used to build cryptographic components like the
MomaKdf(Key Derivation Function). - Prime Number Utilities: A helper
primesmodule for efficient primality testing and prime generation. - Pure Rust: Built with safe, idiomatic Rust.
Installation
Add MOMA to your Cargo.toml:
[]
= "0.1.0"
Quick Start
The easiest way to get started is to create a MomaRing and calculate the "signature" of a prime. The signature is the MOMA residue of the sum of a prime and its predecessor.
use MomaRing;
use primes;
use strategy;
Exploring Further
MOMA is more than just a simple calculator; it's a toolkit for exploration.
Example 1: Prime Gap Analysis
You can use the PrimeGapField analyser to find statistical outliers in the sequence of primes.
// main.rs from the `moma-analysis` example
use PrimeGapField;
use primes;
// Generate primes up to 100
let primes: = .filter.collect;
// Create a field to analyze gaps modulo 6
let field = new;
// Find gaps that are significantly larger or smaller than their local average
let outliers = field.filter_by_bary_offset;
println!;
for gap in outliers
Example 2: Cryptographic Key Derivation
MOMA can be used as a building block for cryptographic functions. The included MomaKdf example shows how to use it as a password-stretching function.
// main.rs from the `moma-kdf` example
// [Note: This requires the sha2 and hex crates]
// Create a KDF instance
let kdf = new;
// Derive a strong 256-bit key
let key = kdf.derive_key;
println!;
Contributing
Contributions are welcome! If you have an idea for a new OriginStrategy, an analysis tool, or find a bug, please feel free to open an issue or submit a pull request.
License
This project is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.