gallois sucks
This commit is contained in:
parent
c29b08487e
commit
1246d84267
|
@ -26,16 +26,16 @@ pub const INFINITY_POINT: ElipticCurvePoint = ElipticCurvePoint {
|
||||||
///
|
///
|
||||||
/// real curves not supported, only in Gallois Fields
|
/// real curves not supported, only in Gallois Fields
|
||||||
pub struct ElipticCurve {
|
pub struct ElipticCurve {
|
||||||
f: Option<GalloisField>,
|
f: GalloisField,
|
||||||
a: i128,
|
a: i128,
|
||||||
b: i128,
|
b: i128,
|
||||||
points: Vec<ElipticCurvePoint>,
|
points: Vec<ElipticCurvePoint>,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
INFINITY_POINT: ElipticCurvePoint
|
INFINITY_POINT: ElipticCurvePoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElipticCurve {
|
impl ElipticCurve {
|
||||||
pub fn new(f: Option<GalloisField>, a: i128, b: i128, verbose: bool) -> Self {
|
pub fn new(f: GalloisField, a: i128, b: i128, verbose: bool) -> Self {
|
||||||
let e = ElipticCurve {
|
let e = ElipticCurve {
|
||||||
f,
|
f,
|
||||||
a,
|
a,
|
||||||
|
@ -48,6 +48,7 @@ impl ElipticCurve {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
/// represent a specific eliptic curves point
|
/// represent a specific eliptic curves point
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
/// calculation in a gallois field
|
/// calculation in a gallois field
|
||||||
///
|
///
|
||||||
/// This module contains functions that can be used to calculate things in a gallois field
|
/// This module contains functions that can be used to calculate things in a gallois field
|
||||||
|
/// TODO I'm not sure how accurate it is to call this stuff a gallois field.
|
||||||
|
/// They should normally be based on some relation and not use numbers?
|
||||||
|
/// It does also not even come close to statisfying the characteristic of prime powers q = p^k.as
|
||||||
|
/// base => p = 0
|
||||||
|
///
|
||||||
|
/// Something is wrong here.
|
||||||
///
|
///
|
||||||
/// Author: Christoph J. Scherr <software@cscherr.de>
|
/// Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
/// License: MIT
|
/// License: MIT
|
||||||
|
@ -15,6 +21,8 @@ use num::Integer;
|
||||||
|
|
||||||
use pyo3::{prelude::*, exceptions::PyValueError};
|
use pyo3::{prelude::*, exceptions::PyValueError};
|
||||||
|
|
||||||
|
use primes::{Sieve, PrimeSet, is_prime};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#[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.
|
||||||
|
@ -59,9 +67,8 @@ pub struct GalloisField {
|
||||||
impl GalloisField {
|
impl GalloisField {
|
||||||
/// make a new gallois field
|
/// make a new gallois field
|
||||||
pub fn new(base: u128, verbose: bool) -> Self {
|
pub fn new(base: u128, verbose: bool) -> Self {
|
||||||
let field = GalloisField{
|
let mut field = GalloisField{
|
||||||
base,
|
base,
|
||||||
// TODO: calculate the characteristic
|
|
||||||
cha: 0,
|
cha: 0,
|
||||||
verbose
|
verbose
|
||||||
};
|
};
|
||||||
|
@ -296,6 +303,25 @@ impl GalloisField {
|
||||||
return Ok((w1, w2));
|
return Ok((w1, w2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// calculate the characteristic of the field
|
||||||
|
pub fn calc_char(mut self) -> u128 {
|
||||||
|
if self.verbose {
|
||||||
|
seperator();
|
||||||
|
println!("calculating characteristic of F_{}", self.base);
|
||||||
|
seperator();
|
||||||
|
}
|
||||||
|
let mut i = 1u128;
|
||||||
|
while self.reduce(i) > 0 {
|
||||||
|
if self.verbose {
|
||||||
|
println!("{i}.\t {i} = {} (mod {})", self.reduce(i), self.base)
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cha = i;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
|
@ -378,3 +404,13 @@ fn test_gallois_inverse() {
|
||||||
|
|
||||||
// TODO add a test for a field that has a non prime base
|
// TODO add a test for a field that has a non prime base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_calc_char() {
|
||||||
|
assert_eq!(GalloisField::new(16, true).calc_char(), 2);
|
||||||
|
assert_eq!(GalloisField::new(81, true).calc_char(), 81);
|
||||||
|
assert_eq!(GalloisField::new(1151, true).calc_char(), 1151);
|
||||||
|
assert_eq!(GalloisField::new(8, true).calc_char(), 2);
|
||||||
|
assert_eq!(GalloisField::new(2, true).calc_char(), 2);
|
||||||
|
assert_eq!(GalloisField::new(60, true).calc_char(), 3);
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn alt_egcd(mut a: i128, mut b: i128, recursion: bool) -> Vec<i128> {
|
||||||
return vec![b, 0, 1]
|
return vec![b, 0, 1]
|
||||||
}
|
}
|
||||||
let v = alt_egcd(b % a, a, true);
|
let v = alt_egcd(b % a, a, true);
|
||||||
let mut result = vec![
|
let result = vec![
|
||||||
v[0],
|
v[0],
|
||||||
v[2] - (b.checked_div(a).unwrap()) * v[1],
|
v[2] - (b.checked_div(a).unwrap()) * v[1],
|
||||||
v[1],
|
v[1],
|
||||||
|
|
Loading…
Reference in New Issue