WIP: feat: gfmul working but LSB check is broken

This commit is contained in:
0xalivecow 2024-10-26 13:04:26 +02:00
parent 1f8e2c75c8
commit 4dc6cdfef8
No known key found for this signature in database
5 changed files with 231 additions and 22 deletions

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use base64::prelude::*;
use std::{str::FromStr, u128, u8};
use std::{str::FromStr, u128, u8, usize};
pub fn get_alpha_rep(num: u128) -> String {
let powers: Vec<u8> = get_coefficients(num);
@ -55,6 +55,16 @@ pub fn get_bit_indices_from_byte(byte: u8) -> Vec<u8> {
coefficients
}
pub fn coefficients_to_byte_arr_xex(coeffs: Vec<u8>) -> Vec<u8> {
let mut byte_array: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for coeff in coeffs {
let block_num = coeff / 8;
byte_array[usize::from(block_num)] |= (1 << (coeff % 7));
}
byte_array
}
pub fn coefficient_to_binary(coefficients: Vec<u8>) -> u128 {
let mut binary_number: u128 = 0;
for coeff in coefficients {
@ -71,6 +81,24 @@ mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn coefficients_to_byte_arr_xex_test1() {
let coefficients: Vec<u8> = vec![0];
let byte_array = vec![
01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
];
assert_eq!(coefficients_to_byte_arr_xex(coefficients), byte_array)
}
#[test]
fn coefficients_to_byte_arr_xex_test2() {
let coefficients: Vec<u8> = vec![127, 12, 9, 0];
let byte_array = vec![
01, 12, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 80,
];
assert_eq!(coefficients_to_byte_arr_xex(coefficients), byte_array)
}
#[test]
fn byte_indices_0x01() {
let byte: u8 = 0x01;