#[allow(dead_code)]
pub fn u8arr_to_hex(u8_array: Vec<u8>) -> String {
    u8_array.iter().map(|x| format!("{x:02x}")).collect()
}


pub fn u32arr_to_u8arr(u32_array: Vec<u32>) -> Vec<u8> {
    let mut u8_array: Vec<u8> = Vec::new();

    for i in 0..u32_array.len() {
        u8_array.push((u32_array[i] >> 24) as u8);
        u8_array.push((u32_array[i] >> 16) as u8);
        u8_array.push((u32_array[i] >> 8) as u8);
        u8_array.push(u32_array[i] as u8);
    }

    u8_array
}


pub fn u8arr_to_u32arr(u8_array: Vec<u8>) -> Vec<u32> {
    let len = u8_array.len() / 4;
    let mut u32_array = vec![0u32; len];

    for i in 0..len {
        u32_array[i] = ((u8_array[i * 4] as u32) << 24) |
                    ((u8_array[i * 4 + 1] as u32) << 16) |
                    ((u8_array[i * 4 + 2] as u32) << 8) |
                    (u8_array[i * 4 + 3] as u32);
    }

    u32_array
}


pub fn u32_add(u32_array: &[u32]) -> u32 {
    let mut sum: u32 = 0;
    for x in u32_array {
        sum = sum.wrapping_add(*x);
    }

    sum
}


pub fn u8arr_xor(u8_array1: Vec<u8>, u8_array2: Vec<u8>) -> Vec<u8> {
    u8_array1.iter().enumerate().map(|(i, x)| x ^ u8_array2[i]).collect()
}
