From ebfce5ac7f07af008ddb8cf7ac99bfc88f975950 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 13 May 2023 17:08:56 +0200 Subject: [PATCH] some changes idk --- Cargo.toml | 2 +- src/lib.rs | 1 + src/main.rs | 2 +- src/math/pm1.rs | 13 ++++++++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2429e32..098fd0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "plexcryptool" -version = "0.2.0" +version = "0.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 01ba2d0..8cd3b18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,7 @@ fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> { let math_module = PyModule::new(py, "math")?; math_module.add_function(wrap_pyfunction!(math::modexp::py_modular_exponentiation, math_module)?)?; + math_module.add_function(wrap_pyfunction!(math::pm1::py_p_minus_one, math_module)?)?; parent_module.add_submodule(math_module)?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 9d5feab..94399ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ use num_bigint; /*************************************************************************************************/ // This is just structures for parsing Cli args #[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] +#[clap(name="plexcryptool", author="Christoph J. Scherr", version, about="Various tools for use with math and cryptology, includes executable and a library.")] struct Cli { /// Which submodule to use #[command(subcommand)] diff --git a/src/math/pm1.rs b/src/math/pm1.rs index 5c3b565..bca5238 100644 --- a/src/math/pm1.rs +++ b/src/math/pm1.rs @@ -8,7 +8,7 @@ /// License: MIT /// Source: -use pyo3::prelude::*; +use pyo3::{prelude::*, exceptions::PyArithmeticError}; use num::integer::gcd; @@ -93,6 +93,17 @@ pub fn p_minus_one(n: u128, max_prime: u128, verbose: bool) -> Result, return Ok(prime_parts); } +#[pyfunction] +#[pyo3(name = "p_minus_one")] +/// python wrapper for p_minus_one +pub fn py_p_minus_one(n: u128, max_prime: u128, verbose: bool)-> PyResult> { + let res = p_minus_one(n, max_prime, verbose); + match res { + Ok(vec) => Ok(vec), + Err(e) => Err(PyArithmeticError::new_err(e)) + } +} + /// alternative simple implementation for gcd pub fn alt_gcd(mut a: u128, mut b: u128) -> u128 { let mut tmp: u128;