use byteorder::ByteOrder;
use rand_mt::Mt64;

const SIZE: usize = 4096;
pub struct MhyXorpad([u8; SIZE]);

impl MhyXorpad {
    #[must_use]
    pub fn new<E: ByteOrder>(seed: u64) -> Self {
        let mut mt = Mt64::new(seed);
        let mut buf = [0u8; 4096];

        (0..(SIZE >> 3)).for_each(|i| E::write_u64(&mut buf[i * 8..(i + 1) * 8], mt.next_u64()));
        Self(buf)
    }

    pub fn xor(&self, buf: &mut [u8]) {
        buf.iter_mut()
            .enumerate()
            .for_each(|(i, v)| *v ^= self.0[i % SIZE]);
    }
}
