inverse maybe fix
This commit is contained in:
parent
9d2a972cc9
commit
e3e122f066
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue