inverse maybe fix

This commit is contained in:
Christoph J. Scherr 2023-05-30 12:05:05 +02:00
parent 9d2a972cc9
commit e3e122f066
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
2 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,8 @@
#![allow(dead_code)] #![allow(dead_code)]
/// eliptic curve cryptography /// eliptic curve cryptography
/// ///
/// This module implements structs and functionalities used for ECC. /// This module implements structs and functionalities used for eliptic curve cryptography (ECC).
/// Do not expect it to actually be secure, I made this for cryptography lectures.
/// ///
/// Author: Christoph J. Scherr <software@cscherr.de> /// Author: Christoph J. Scherr <software@cscherr.de>
/// License: MIT /// License: MIT

View File

@ -18,7 +18,6 @@
use crate::{math::modexp, cplex::printing::seperator}; use crate::{math::modexp, cplex::printing::seperator};
use core::fmt; use core::fmt;
use std::{fmt::Debug, ops::{AddAssign, Add}};
use num::Integer; use num::Integer;
@ -394,7 +393,7 @@ impl GalloisField {
/// get multiplicative inverse /// get multiplicative inverse
pub fn py_inverse(&self, n: u128) -> PyResult<u128> { pub fn py_inverse(&self, n: u128) -> PyResult<u128> {
match self.inverse(n) { match self.inverse(n) {
Ok(v) => Ok(v), Ok(v) => {return Ok(v)},
Err(e) => { Err(e) => {
let py_e = PyValueError::new_err(e.to_string()); let py_e = PyValueError::new_err(e.to_string());
return Err(py_e) return Err(py_e)
@ -424,6 +423,11 @@ fn test_gallois_inverse() {
assert_eq!(field.inverse(54).unwrap(), 20); assert_eq!(field.inverse(54).unwrap(), 20);
assert!(field.inverse(0).is_err()); assert!(field.inverse(0).is_err());
let field = GalloisField::new(23, true);
assert_eq!(field.inverse(17).unwrap(), 19);
assert_eq!(field.inverse(7).unwrap(), 10);
assert!(field.inverse(0).is_err());
// TODO i think this test does not catch all edge cases. In some cases, something seems to be // TODO i think this test does not catch all edge cases. In some cases, something seems to be
// wrong. // wrong.