gallois python compat
This commit is contained in:
parent
aa839ed1e1
commit
4943a7d47c
|
@ -0,0 +1,23 @@
|
||||||
|
"""
|
||||||
|
gallois field calculations
|
||||||
|
|
||||||
|
Implements a number of calculations in gallois fields. Use the GalloisFiled struct/class and it's methods.
|
||||||
|
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
class GalloisFiled:
|
||||||
|
def __init__(self, base: int, verbose: bool) -> None:
|
||||||
|
"""
|
||||||
|
Create a new Gallois field
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def reduce(self, n: int) -> int:
|
||||||
|
"""
|
||||||
|
reduce the given number to fit into the field
|
||||||
|
"""
|
|
@ -13,6 +13,8 @@ use core::fmt;
|
||||||
|
|
||||||
use num::Integer;
|
use num::Integer;
|
||||||
|
|
||||||
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// used when trying to find a root for a number which does not have a root.
|
/// used when trying to find a root for a number which does not have a root.
|
||||||
|
@ -45,6 +47,7 @@ impl fmt::Display for NoRootError {
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
#[pyclass]
|
||||||
/// represent a gallois field
|
/// represent a gallois field
|
||||||
pub struct GalloisFiled {
|
pub struct GalloisFiled {
|
||||||
base: u128,
|
base: u128,
|
||||||
|
@ -297,6 +300,25 @@ impl GalloisFiled {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
/// python wrappers for the gallois field
|
||||||
|
impl GalloisFiled {
|
||||||
|
#[new]
|
||||||
|
pub fn py_new(base: u128, verbose: bool) -> Self {
|
||||||
|
return GalloisFiled::new(base, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyo3(name="reduce")]
|
||||||
|
/// reduce any int
|
||||||
|
pub fn py_reduce(&self, n: i128) -> u128 {
|
||||||
|
if n.is_negative() {
|
||||||
|
return self.reduce_neg(n);
|
||||||
|
}
|
||||||
|
return self.reduce(n as u128);
|
||||||
|
}
|
||||||
|
// TODO implement wrappers for all other gallois methods
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gallois_sqrt() {
|
fn test_gallois_sqrt() {
|
||||||
|
|
Loading…
Reference in New Issue