feat: gfmul fix algorithm. test is passing.
This commit is contained in:
parent
4dc6cdfef8
commit
7564869ea8
2 changed files with 24 additions and 5 deletions
|
|
@ -44,10 +44,13 @@ pub fn gfmul(args: &Value) -> Result<String> {
|
||||||
|
|
||||||
if poly2.LSB_is_one() {
|
if poly2.LSB_is_one() {
|
||||||
result.xor_byte_arrays(&poly1);
|
result.xor_byte_arrays(&poly1);
|
||||||
|
poly2.right_shift();
|
||||||
|
} else {
|
||||||
|
poly2.right_shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
while !poly2.is_empty() {
|
while !poly2.is_empty() {
|
||||||
if !poly2.LSB_is_one() {
|
if poly2.LSB_is_one() {
|
||||||
poly1.left_shift();
|
poly1.left_shift();
|
||||||
poly1.xor_byte_arrays(&red_poly_bytes);
|
poly1.xor_byte_arrays(&red_poly_bytes);
|
||||||
eprintln!("Poly1 after reduction: {:01X?}", poly1);
|
eprintln!("Poly1 after reduction: {:01X?}", poly1);
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_byte_array_shift2() {
|
fn test_byte_array_shift2() {
|
||||||
let mut byte_array: ByteArray = ByteArray(vec![0x00, 0xFF]);
|
let mut byte_array: ByteArray = ByteArray(vec![0xFF, 0x00]);
|
||||||
let shifted_array: ByteArray = ByteArray(vec![0x01, 0xFE]);
|
let shifted_array: ByteArray = ByteArray(vec![0xFE, 0x01]);
|
||||||
byte_array.left_shift();
|
byte_array.left_shift();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -80,13 +80,29 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_byte_array_shift_right() {
|
||||||
|
let mut byte_array: ByteArray = ByteArray(vec![0x02]);
|
||||||
|
let shifted_array: ByteArray = ByteArray(vec![0x01]);
|
||||||
|
byte_array.right_shift();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
byte_array.0, shifted_array.0,
|
||||||
|
"Failure: Shifted array was: {:?}",
|
||||||
|
byte_array.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lsb_one() {
|
fn test_lsb_one() {
|
||||||
let mut byte_array: ByteArray = ByteArray(vec![0x00, 0xFF]);
|
let mut byte_array: ByteArray = ByteArray(vec![0x00, 0xFF]);
|
||||||
assert!(byte_array.LSB_is_one());
|
assert!(!byte_array.LSB_is_one());
|
||||||
|
|
||||||
let mut byte_array2: ByteArray = ByteArray(vec![0x00, 0x02]);
|
let mut byte_array2: ByteArray = ByteArray(vec![0x02, 0xFF]);
|
||||||
assert!(!byte_array2.LSB_is_one());
|
assert!(!byte_array2.LSB_is_one());
|
||||||
|
|
||||||
|
let mut byte_array3: ByteArray = ByteArray(vec![0xFF, 0x00]);
|
||||||
|
assert!(byte_array3.LSB_is_one());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue